On this page
types.GenericAlias
Prev: types.GeneratorType | Up: types | Next: types.get_original_bases
Rel: types.AsyncGeneratorType, types.BuiltinFunctionType, types.BuiltinMethodType, types.CapsuleType
Ref: docs.python.org — types.GenericAlias
Tags: #public #python3 #stdlib #types
Import
import types
from types import GenericAlias
Signature & Overview
types.GenericAlias(origin, args, /)
Represent a PEP 585 generic type For example, for t = list[int], t.origin is list and t.args is (int,).
Usage
import types
alias = list[int]
assert isinstance(alias, types.GenericAlias) and alias.__origin__ is list and alias.__args__ == (int,)
Gotchas
- Runtime type created by PEP 585 built-in generics (
list[int],dict[str, float]).
REPL Inspect
from types import GenericAlias
help(GenericAlias)
Linked from
Related notes
- tuts/python3/stdlib_module/types/GeneratorType Linked here; links to this page; shared tags: #stdlib, #types
- tuts/python3/stdlib_module/types/get_original_bases Linked here; links to this page; shared tags: #stdlib, #types
- tuts/python3/stdlib_module/types Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/types/AsyncGeneratorType Linked here; shared tags: #stdlib, #types
- tuts/python3/stdlib_module/types/BuiltinFunctionType Linked here; shared tags: #stdlib, #types
- tuts/python3/stdlib_module/types/BuiltinMethodType Linked here; shared tags: #stdlib, #types
- tuts/python3/stdlib_module/types/CapsuleType Linked here; shared tags: #stdlib, #types
- tuts/c/stdlib/stdint_stdbool_and_limits shared tags: #stdlib, #types
- tuts/python3/stdlib_module/types/CellType shared tags: #stdlib, #types
- tuts/python3/stdlib_module/types/ClassMethodDescriptorType shared tags: #stdlib, #types