Strip the annotations from a given type.
(t)
| 2456 | |
| 2457 | |
| 2458 | def _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 | |
| 2483 | def get_origin(tp): |
no test coverage detected