bpo-46553: allow bare typing.ClassVar annotations by GBeauregard · Pull Request #30983 · python/cpython
These are used in the wild and covered by dataclasses unit tests. Several static type checkers support this pattern. Note we adjust one test from ClassVar[ClassVar] to ClassVar[ClassVar[int]] so that it still fails. This is surprising, but not a result of weirdness we're doing in this patch. This is a limitation of the current way runtime type checking works that this case is allowed when bare special forms are allowed. For example, before this patch `ClassVar[Final]` is a valid annotation despite nesting these forms being generally disallowed. Addressing this limitation could be future work.
GBeauregard
changed the title
typing: allow bare ClassVar annotations
bpo-46553: allow bare typing.ClassVar annotations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters