gotmax23 · GitHub

Bug report

Bug description:

from annotationlib import get_annotations
from _colorize import ThemeSection
get_annotations(ThemeSection) # NameError: name 'ClassVar' is not defined

See the above reproducer and beartype/beartype#656 for more context. The issue here is that the _colorize module (which is imported by other public modules/packages in the stdlib) guards its typing imports (which are used in dataclass field annotations) in an if False: block. This breaks runtime type checkers like beartype that introspect type annotations at runtime.

CPython versions tested on:

3.15

Operating systems tested on:

Linux

Linked PRs

Read the original on github.com ↗