Skip to content

Typing spec update: ClassVar and Final within TypedDict #39

Closed
@InSyncWithFoo

Description

@InSyncWithFoo

As discussed in the thread linked above, major type checkers currently don't consider such a ClassVar an error.

As for Final, Pyright and Mypy do reports it, but their messages are unclear; Pytype and Pyre, on the other hand, ignores such items completely:

(playgrounds: Pyright, Mypy, Pyre)

class TD(TypedDict):
    v: ClassVar[int]     # all     => fine

    f: Final[int]        # pyright => error: "f" is declared Final, but value is not assigned
                         # mypy    => error: Final can be only used as an outermost qualifier in a variable annotation
                         # pyre    => fine
                         # pytype  => fine

    a: Final[int] = 42   # pyright => error: TypedDict classes can contain only type annotations
                         # mypy    => error: Right hand side values are not supported in TypedDict
                         # pyre    => fine
                         # pytype  => fine

Reference implementation: None.

TC Sign-off

  • Carl
  • Eric
  • Jelle
  • Jukka
  • Rebecca

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions