1. 5

    I really wish that instead of data classes, which force me to invent types for my data, we’d get a nice built-in syntax for named tuples that wouldn’t require importing a module and repeating the record name twice.

    1. 3

      I really wish that instead of data classes, which force me to invent types for my data, we’d get a nice built-in syntax for named tuples that wouldn’t require importing a module and repeating the record name twice.

      Well, you still have to specify the types of your data and do an import, but there is a nice alternative syntax for named tuples if you want to avoid repeating the record name:

      class Component(NamedTuple):
          part_number: int
          weight: float
          description: Optional[str] = None
      
      1. 1

        Thanks, I didn’t know about the capitalized NamedTuple.

      2. 2

        I agree, the types seem like an unnecessary complication.