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
| Name | Type | Description |
|---|---|---|
| obj | object | Supported annotated object. |
| globalns | dict or None | Global namespace for resolution. |
| localns | dict or None | Local namespace for resolution. |
| include_extras | bool | Retain 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})