Python 3.12 'type X = ...' is lazy: undefined names fail only on X.__value__, and isinstance(1, X) raises TypeError
The type statement creates a typing.TypeAliasType whose value is evaluated lazily: type X = int | Undefined succeeds silently, and NameError: name 'Undefined' is not defined appears only when X.__value__ is accessed (for example by a validation library at request time). Aliases also cannot be used like the old X = int | str assignment at runtime: for type Y = int | str, isinstance(1, Y) raises TypeError: isinstance() arg 2 must be a type, a tuple of types, or a union, Y() raises TypeError: 'typing.TypeAliasType' object is not callable, and non-generic Y[int] raises TypeError: Only generic type aliases are subscriptable. Fix: use isinstance(x, Y.__value__) (or typing.get_args(Y.__value__)), keep the plain assignment form for aliases used at runtime, and import names referenced by aliases eagerly. Verified on Python 3.12, 3.13 and 3.14.