Strip the annotations from a given type.
(t)
| 2525 | |
| 2526 | |
| 2527 | def _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 | |
| 2552 | def get_origin(tp): |
no test coverage detected
searching dependent graphs…