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

Function _strip_annotations

Lib/typing.py:2458–2480  ·  view source on GitHub ↗

Strip the annotations from a given type.

(t)

Source from the content-addressed store, hash-verified

2456
2457
2458def _strip_annotations(t):
2459 """Strip the annotations from a given type."""
2460 if isinstance(t, _AnnotatedAlias):
2461 return _strip_annotations(t.__origin__)
2462 if hasattr(t, "__origin__") and t.__origin__ in (Required, NotRequired, ReadOnly):
2463 return _strip_annotations(t.__args__[0])
2464 if isinstance(t, _GenericAlias):
2465 stripped_args = tuple(_strip_annotations(a) for a in t.__args__)
2466 if stripped_args == t.__args__:
2467 return t
2468 return t.copy_with(stripped_args)
2469 if isinstance(t, GenericAlias):
2470 stripped_args = tuple(_strip_annotations(a) for a in t.__args__)
2471 if stripped_args == t.__args__:
2472 return t
2473 return GenericAlias(t.__origin__, stripped_args)
2474 if isinstance(t, Union):
2475 stripped_args = tuple(_strip_annotations(a) for a in t.__args__)
2476 if stripped_args == t.__args__:
2477 return t
2478 return functools.reduce(operator.or_, stripped_args)
2479
2480 return t
2481
2482
2483def get_origin(tp):

Callers 1

get_type_hintsFunction · 0.85

Calls 5

GenericAliasFunction · 0.90
isinstanceFunction · 0.85
hasattrFunction · 0.85
copy_withMethod · 0.45
reduceMethod · 0.45

Tested by

no test coverage detected