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

Function get_origin

Lib/typing.py:2552–2579  ·  view source on GitHub ↗

Get the unsubscripted version of a type. This supports generic types, Callable, Tuple, Union, Literal, Final, ClassVar, Annotated, and others. Return None for unsupported types. Examples:: >>> P = ParamSpec('P') >>> assert get_origin(Literal[42]) is Literal >>>

(tp)

Source from the content-addressed store, hash-verified

2550
2551
2552def get_origin(tp):
2553 """Get the unsubscripted version of a type.
2554
2555 This supports generic types, Callable, Tuple, Union, Literal, Final, ClassVar,
2556 Annotated, and others. Return None for unsupported types.
2557
2558 Examples::
2559
2560 >>> P = ParamSpec('P')
2561 >>> assert get_origin(Literal[42]) is Literal
2562 >>> assert get_origin(int) is None
2563 >>> assert get_origin(ClassVar[int]) is ClassVar
2564 >>> assert get_origin(Generic) is Generic
2565 >>> assert get_origin(Generic[T]) is Generic
2566 >>> assert get_origin(Union[T, int]) is Union
2567 >>> assert get_origin(List[Tuple[T, T]][int]) is list
2568 >>> assert get_origin(P.args) is P
2569 """
2570 if isinstance(tp, _AnnotatedAlias):
2571 return Annotated
2572 if isinstance(tp, (_BaseGenericAlias, GenericAlias,
2573 ParamSpecArgs, ParamSpecKwargs)):
2574 return tp.__origin__
2575 if tp is Generic:
2576 return Generic
2577 if isinstance(tp, Union):
2578 return Union
2579 return None
2580
2581
2582def get_args(tp):

Callers 7

test_get_originMethod · 0.90
test_basicsMethod · 0.90
test_basicsMethod · 0.90
test_get_originMethod · 0.90

Calls

no outgoing calls

Tested by 6

test_get_originMethod · 0.72
test_basicsMethod · 0.72
test_basicsMethod · 0.72
test_get_originMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…