On this page
typing.get_type_hints
Prev: typing.get_protocol_members | Up: typing | Next: typing.IO
Rel: typing.AbstractSet, typing.Annotated, typing.Any, typing.assert_never
Ref: docs.python.org — typing.get_type_hints
Tags: #public #python3 #stdlib #typing
Import
import typing
from typing import get_type_hints
Signature & Overview
typing.get_type_hints(obj, globalns=None, localns=None, include_extras=False, *, format=None)
Return type hints for an object.
Usage
from typing import get_type_hints
def add(a: int, b: int) -> int:
return a + b
assert get_type_hints(add) == {"a": int, "b": int, "return": int}
Gotchas
- Resolves stringified forward references (
from __future__ import annotations): Unlike readingfn.__annotations__directly,get_type_hints()evaluates string hints into real types—passinclude_extras=Trueto keepAnnotatedmetadata.
REPL Inspect
from typing import get_type_hints
help(get_type_hints)
Linked from
Related notes
- tuts/python3/stdlib_module/typing/get_protocol_members Linked here; links to this page; shared tags: #stdlib, #typing
- tuts/python3/stdlib_module/typing/IO Linked here; links to this page; shared tags: #stdlib, #typing
- tuts/python3/stdlib_module/typing Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/typing/AbstractSet Linked here; shared tags: #stdlib, #typing
- tuts/python3/stdlib_module/typing/Annotated Linked here; shared tags: #stdlib, #typing
- tuts/python3/stdlib_module/typing/Any Linked here; shared tags: #stdlib, #typing
- tuts/python3/stdlib_module/typing/assert_never Linked here; shared tags: #stdlib, #typing
- tuts/python3/stdlib_module/typing/assert_type shared tags: #stdlib, #typing
- tuts/python3/stdlib_module/typing/AsyncContextManager shared tags: #stdlib, #typing
- tuts/python3/stdlib_module/typing/AsyncGenerator shared tags: #stdlib, #typing