MCPcopy Index your code
hub / github.com/python/typing / _strip_extras

Function _strip_extras

typing_extensions/src/typing_extensions.py:819–841  ·  view source on GitHub ↗

Strips Annotated, Required and NotRequired from a given type.

(t)

Source from the content-addressed store, hash-verified

817
818 # replaces _strip_annotations()
819 def _strip_extras(t):
820 """Strips Annotated, Required and NotRequired from a given type."""
821 if isinstance(t, _AnnotatedAlias):
822 return _strip_extras(t.__origin__)
823 if hasattr(t, "__origin__") and t.__origin__ in (Required, NotRequired):
824 return _strip_extras(t.__args__[0])
825 if isinstance(t, typing._GenericAlias):
826 stripped_args = tuple(_strip_extras(a) for a in t.__args__)
827 if stripped_args == t.__args__:
828 return t
829 return t.copy_with(stripped_args)
830 if hasattr(types, "GenericAlias") and isinstance(t, types.GenericAlias):
831 stripped_args = tuple(_strip_extras(a) for a in t.__args__)
832 if stripped_args == t.__args__:
833 return t
834 return types.GenericAlias(t.__origin__, stripped_args)
835 if hasattr(types, "UnionType") and isinstance(t, types.UnionType):
836 stripped_args = tuple(_strip_extras(a) for a in t.__args__)
837 if stripped_args == t.__args__:
838 return t
839 return functools.reduce(operator.or_, stripped_args)
840
841 return t
842
843 def get_type_hints(obj, globalns=None, localns=None, include_extras=False):
844 """Return type hints for an object.

Callers 1

get_type_hintsFunction · 0.85

Calls 1

copy_withMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…