ID EN
Typing

get_type_hints

Python 3.11

Return a dictionary containing type hints for a function, method, module or class object.

Syntax

PYTHON
typing.get_type_hints(obj, globalns=None, localns=None, include_extras=False)

Examples

Example 1
PYTHON
class Student(NamedTuple):
    name: Annotated[str, 'some marker']

assert get_type_hints(Student) == {'name': str}
assert get_type_hints(Student, include_extras=False) == {'name': str}
assert get_type_hints(Student, include_extras=True) == {
    'name': Annotated[str, 'some marker']
}

See Also

Annotated get_type_hints() type aliases Annotated