Typing and Generics
typing.get_origin
Returns the unsubscripted origin of a supported generic or typing construct; returns None for unsupported objects. For legacy aliases it normalizes to the underlying class where appropriate.
Formal Syntax & Structure
python syntaxpython
typing.get_origin(tp)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| tp | object | Type expression to inspect. |
Return Value
object or None
Typing construct or runtime result as described; static typing rules are not runtime validation.
Working Example
Example Snippetpython
from typing import Mapping, get_origin
from collections.abc import Mapping as ABCMappingprint((get_origin(list[int]) is list, get_origin(Mapping[str,int]) is ABCMapping))