MCPcopy Index your code
hub / github.com/RustPython/RustPython / get_args

Function get_args

Lib/typing.py:2513–2536  ·  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

2511
2512
2513def get_args(tp):
2514 """Get type arguments with all substitutions performed.
2515
2516 For unions, basic simplifications used by Union constructor are performed.
2517
2518 Examples::
2519
2520 >>> T = TypeVar('T')
2521 >>> assert get_args(Dict[str, int]) == (str, int)
2522 >>> assert get_args(int) == ()
2523 >>> assert get_args(Union[int, Union[T, int], str][int]) == (int, str)
2524 >>> assert get_args(Union[int, Tuple[T, int]][str]) == (int, Tuple[str, int])
2525 >>> assert get_args(Callable[[], T][int]) == ([], int)
2526 """
2527 if isinstance(tp, _AnnotatedAlias):
2528 return (tp.__origin__,) + tp.__metadata__
2529 if isinstance(tp, (_GenericAlias, GenericAlias)):
2530 res = tp.__args__
2531 if _should_unflatten_callable_args(tp, res):
2532 res = (list(res[:-1]), res[-1])
2533 return res
2534 if isinstance(tp, Union):
2535 return tp.__args__
2536 return ()
2537
2538
2539def 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 3

isinstanceFunction · 0.85
listClass · 0.85

Tested by 14

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