gh-144190: Clarify get_type_hints() instance behavior in docs by iamrajhans · Pull Request #144831 · python/cpython
Summary
Document typing.get_type_hints() behavior for instance objects in Python 3.14+.
- Clarify that
get_type_hints()is intended for modules, classes, and callables. - Add an explicit note that calling
get_type_hints()on instances is not supported. - Recommend
get_type_hints(type(obj))for instance use cases. - Add a
versionchanged:: 3.14note explaining that instance support in earlier versions was undocumented behavior.
Why
Issue #144190 reported a regression when calling get_type_hints(self) in a dataclass __init__.
Core-dev discussion confirmed this is intentional in 3.14 and should be documented.
Testing
Docs-only change; no runtime behavior changed.
📚 Documentation preview 📚: https://cpython-previews--144831.org.readthedocs.build/