On this page
typing.get_args
Prev: typing.Generic | Up: typing | Next: typing.get_origin
Rel: typing.AbstractSet, typing.Annotated, typing.Any, typing.assert_never
Ref: docs.python.org — typing.get_args
Tags: #public #python3 #stdlib #typing
Import
import typing
from typing import get_args
Signature & Overview
typing.get_args(tp)
Get type arguments with all substitutions performed.
Usage
from typing import get_args
assert get_args(dict[str, int]) == (str, int)
assert get_args(int) == ()
Gotchas
- Returns
()for non-generic types: Pair withget_origin()to build runtime serializers, validators, or DI containers.
REPL Inspect
from typing import get_args
help(get_args)
Linked from
Related notes
- tuts/python3/stdlib_module/typing/Generic Linked here; links to this page; shared tags: #stdlib, #typing
- tuts/python3/stdlib_module/typing/get_origin Linked here; links to this page; shared tags: #stdlib, #typing
- tuts/python3/stdlib_module/typing Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/typing/AbstractSet Linked here; shared tags: #stdlib, #typing
- tuts/python3/stdlib_module/typing/Annotated Linked here; shared tags: #stdlib, #typing
- tuts/python3/stdlib_module/typing/Any Linked here; shared tags: #stdlib, #typing
- tuts/python3/stdlib_module/typing/assert_never Linked here; shared tags: #stdlib, #typing
- tuts/python3/stdlib_module/typing/assert_type shared tags: #stdlib, #typing
- tuts/python3/stdlib_module/typing/AsyncContextManager shared tags: #stdlib, #typing
- tuts/python3/stdlib_module/typing/AsyncGenerator shared tags: #stdlib, #typing