MCPcopy Index your code
hub / github.com/python/cpython / get_args

Function get_args

Lib/typing.py:2582–2605  ·  view source on GitHub ↗

Get type arguments with all substitutions performed. For unions, basic simplifications used by Union constructor are performed. Examples:: >>> T = TypeVar('T') >>> assert get_args(Dict[str, int]) == (str, int) >>> assert get_args(int) == () >>> assert get_a

(tp)

Source from the content-addressed store, hash-verified

2580
2581
2582def get_args(tp):
2583 """Get type arguments with all substitutions performed.
2584
2585 For unions, basic simplifications used by Union constructor are performed.
2586
2587 Examples::
2588
2589 >>> T = TypeVar('T')
2590 >>> assert get_args(Dict[str, int]) == (str, int)
2591 >>> assert get_args(int) == ()
2592 >>> assert get_args(Union[int, Union[T, int], str][int]) == (int, str)
2593 >>> assert get_args(Union[int, Tuple[T, int]][str]) == (int, Tuple[str, int])
2594 >>> assert get_args(Callable[[], T][int]) == ([], int)
2595 """
2596 if isinstance(tp, _AnnotatedAlias):
2597 return (tp.__origin__,) + tp.__metadata__
2598 if isinstance(tp, (_GenericAlias, GenericAlias)):
2599 res = tp.__args__
2600 if _should_unflatten_callable_args(tp, res):
2601 res = (list(res[:-1]), res[-1])
2602 return res
2603 if isinstance(tp, Union):
2604 return tp.__args__
2605 return ()
2606
2607
2608def is_typeddict(tp):

Callers 15

test_aliasMethod · 0.90
test_aliasMethod · 0.90
test_orMethod · 0.90
test_get_argsMethod · 0.90
test_genericMethod · 0.90
test_order_in_unionMethod · 0.90
test_alias_access_01Method · 0.90

Calls 2

listClass · 0.85

Tested by 15

test_aliasMethod · 0.72
test_aliasMethod · 0.72
test_orMethod · 0.72
test_get_argsMethod · 0.72
test_genericMethod · 0.72
test_order_in_unionMethod · 0.72
test_alias_access_01Method · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…