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

Function _strip_annotations

Lib/typing.py:2527–2549  ·  view source on GitHub ↗

Strip the annotations from a given type.

(t)

Source from the content-addressed store, hash-verified

2525
2526
2527def _strip_annotations(t):
2528 """Strip the annotations from a given type."""
2529 if isinstance(t, _AnnotatedAlias):
2530 return _strip_annotations(t.__origin__)
2531 if hasattr(t, "__origin__") and t.__origin__ in (Required, NotRequired, ReadOnly):
2532 return _strip_annotations(t.__args__[0])
2533 if isinstance(t, _GenericAlias):
2534 stripped_args = tuple(_strip_annotations(a) for a in t.__args__)
2535 if stripped_args == t.__args__:
2536 return t
2537 return t.copy_with(stripped_args)
2538 if isinstance(t, GenericAlias):
2539 stripped_args = tuple(_strip_annotations(a) for a in t.__args__)
2540 if stripped_args == t.__args__:
2541 return t
2542 return _rebuild_generic_alias(t, stripped_args)
2543 if isinstance(t, Union):
2544 stripped_args = tuple(_strip_annotations(a) for a in t.__args__)
2545 if stripped_args == t.__args__:
2546 return t
2547 return functools.reduce(operator.or_, stripped_args)
2548
2549 return t
2550
2551
2552def get_origin(tp):

Callers 1

get_type_hintsFunction · 0.85

Calls 3

_rebuild_generic_aliasFunction · 0.85
reduceMethod · 0.80
copy_withMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…