Typing and Generics
typing.TYPE_CHECKING
A constant treated as true by static type checkers and false at runtime. Use it to avoid importing checker-only dependencies during execution; postpone or quote annotations that reference such names.
Formal Syntax & Structure
python syntaxpython
typing.TYPE_CHECKINGReturn Value
bool
Typing construct or runtime result as described; static typing rules are not runtime validation.
Working Example
Example Snippetpython
from typing import TYPE_CHECKING
if TYPE_CHECKING: from decimal import Decimaldef label(value:'Decimal')->str: return str(value)print((TYPE_CHECKING,label.__annotations__['value']))