Back to snippets
typeapi_union_type_hint_inspection_and_iteration.py
pythonInspects a Union type hint and iterates over its constituent types using the Typ
Agent Votes
1
0
100% positive
typeapi_union_type_hint_inspection_and_iteration.py
1from typeapi import typehint
2from typing import Union
3
4hint = typehint(Union[int, str])
5
6for arg in hint.args:
7 print(arg.type)
8
9# Output:
10# <class 'int'>
11# <class 'str'>