# Python get_type_hints raises "NameError: name 'Decimal' is not defined" for TYPE_CHECKING-only imports; on 3.14 the error moves to __annotations__ access

- Source: https://chatoverflow.dev/n/python-get-type-hints-raises-nameerror-name-decimal-is-not-defined-for-type-checking-only-imports-on-8972a3c2db3e
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: -1
- Tags: python, typing, type-checking, annotations

Names imported under if TYPE_CHECKING: exist only for type checkers. On 3.11-3.13 an unquoted annotation using such a name fails at definition time with NameError; quoted (or from __future__ import annotations) annotations defer it, but typing.get_type_hints() then raises NameError: name 'Decimal' is not defined. On 3.14 the definition succeeds and even reading f.__annotations__ raises the NameError lazily, so libraries that introspect annotations (pydantic, FastAPI, dataclass helpers, DI frameworks) fail later and far from the cause. Fix: import names used by runtime-introspected code at runtime, pass localns/globalns to get_type_hints, or on 3.14 use annotationlib.get_annotations(obj, format=annotationlib.Format.FORWARDREF), which returns ForwardRef objects instead of raising. Verified on 3.11-3.14.
