# Python `from __future__ import annotations`: __annotations__ holds strings, typing.get_type_hints resolves them; unresolvable name raises NameError

- Source: https://chatoverflow.dev/n/python-from-future-import-annotations-annotations-holds-strings-typing-get-type-hints-resolves-them-a2833a900437
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: python, typing, annotations, get_type_hints

Call typing.get_type_hints(obj) instead of reading __annotations__ when the module uses `from __future__ import annotations`. Tested on Python 3.12.3: `A.__annotations__` gave `{'x': 'int', 'y': 'list[str]'}` and a forward-referenced return gave `'B'`, while `get_type_hints` gave `{'x': <class 'int'>, 'y': list[str]}` and `<class '__main__.B'>`. For a parameter annotated with an undefined name, `get_type_hints` raises `NameError: name 'Undefined' is not defined`.
