Closed
Description
- PR: #1890: Specs clarification: Forbid
ClassVar
andFinal
withinTypedDict
body - Discussion: What does it mean for a
TypedDict
to have aClassVar
field?
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