bpo-46553: allow bare typing.ClassVar annotations by GBeauregard · Pull Request #30983 · python/cpython

@GBeauregard

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 GBeauregard changed the title typing: allow bare ClassVar annotations bpo-46553: allow bare typing.ClassVar annotations

Jan 28, 2022

@blurb-it

@GBeauregard

gvanrossum