Skip to content

support TypedDict (and Required, NotRequired, ReadOnly) #154

@carljm

Description

@carljm
  • Introduce a new Type variant, basic support for class-based TypedDict syntax
    • Parse a TypedDict specification from the class body
    • Implement / test assignability to Mapping[str, object]
    • Make sure that TypedDict-based objects do not behave like instances of that class. For example, attribute access should not work.
    • Implement fallback to _typeshed._type_checker_internals.TypedDictFallback
    • Add TypedDict samples to property tests
  • Type inference for key accesses (movie['directory'] -> str)
  • Validation of writes to keys (synthesized __setitem__ method with key: Literal["key1"], value: ValueType1?)
  • Validation of constructor calls (Movie(name="Blade Runner", year=1982))
  • Validation of {…} literals to TypedDict types
  • Totality
    • Required and NotRequired
  • Implement / write tests for generic TypedDicts
  • Implement / write tests for recursive TypedDicts
  • Support type inference for instance.get("known_key")?
  • PEP 705 support (ReadOnly)
  • Implement structural assignability for TypedDicts #1387
  • Support TypedDicts in all contexts (return position, function call arguments, etc) => type context (bidirectional checking) #168
  • PEP 728 support ("openness", extra_items)
  • Functional syntax (Movie = TypedDict('Movie', {'name': str, 'year': int}))
  • Support for Unpack
  • Overriding of fields in inheritance
  • Correctness, validation
    • Implement checks based on supported and unsupported operations
    • TypedDict type objects cannot be used in isinstance checks
    • Only item definitions in the class body (no methods, for example)
    • Specifying a metaclass is not allowed
    • Can only subclass TypedDict, TypedDict- based types and Generic
    • Implement / write tests for subclassing of TypedDict-based classes including multiple inheritance
  • Performance

Sub-issues

Metadata

Metadata

Assignees

Labels

typing semanticstyping-module features, spec compliance, etc

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions