Typing and Generics

typing.get_type_hints

Resolves annotations on supported functions, classes and modules; class annotations are merged across the MRO. By default removes Annotated and certain qualifiers. Evaluation can execute arbitrary annotation code: inspect only trusted objects.

Formal Syntax & Structure

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

Parameters & Attributes

NameTypeDescription
objobjectSupported annotated object.
globalnsdict or NoneGlobal namespace for resolution.
localnsdict or NoneLocal namespace for resolution.
include_extrasboolRetain annotation metadata and qualifiers.

Return Value

dict[str, object]

Typing construct or runtime result as described; static typing rules are not runtime validation.

Working Example

Example Snippetpython
from typing import Annotated, get_type_hints
def parse(value:'int')->Annotated[str,'label']: return str(value)print(get_type_hints(parse,globals()) == {'value':int,'return':str})
Python Reference