ID EN
Typing

get_origin

Python 3.11

Get the unsubscripted version of a type: for a typing object of the form X[Y, Z, ...] return X.

Syntax

PYTHON
typing.get_origin(tp)

Examples

Example 1
PYTHON
assert get_origin(str) is None
assert get_origin(Dict[str, int]) is dict
assert get_origin(Union[int, str]) is Union
P = ParamSpec('P')
assert get_origin(P.args) is P
assert get_origin(P.kwargs) is P

See Also

collections ParamSpecArgs ParamSpecKwargs ParamSpec