Python 3.8+typingfunction
typing.get_origin
introspection
Return the unsubscripted origin of a generic: get_origin(list[int]) → list.
Syntax
typing.get_origin(tp)
For anything that isn't a subscripted generic it returns None (get_origin(int) → None), which is the standard runtime test for whether a value is a parameterized generic. It's almost always paired with get_args: the origin says which container, the args say what's inside.
Examples
# Python 3.9+
from typing import get_origin, get_args, Union
print(get_origin(list[int]) is list) # → True
print(get_origin(dict[str, int]) is dict) # → True
print(get_origin(tuple[int, ...]) is tuple) # → True
print(get_origin(Union[int, str]) is Union) # → True
print(get_origin(int)) # → None
print(get_args(list[int])) # → (<class 'int'>,)
See also
Open in the full glossarydocs.python.orgReport an inaccuracy