|
2 | 2 |
|
3 | 3 | from collections import abc |
4 | 4 | from collections.abc import Collection, Mapping |
5 | | -from typing import Any, AnyStr, Final, ForwardRef, Generic, Literal, TypeVar, Union, _SpecialForm |
| 5 | +from typing import ( |
| 6 | + Any, |
| 7 | + AnyStr, |
| 8 | + Final, |
| 9 | + ForwardRef, |
| 10 | + Generic, |
| 11 | + Literal, |
| 12 | + TypeVar, |
| 13 | + Union, |
| 14 | + _SpecialForm, # pyright: ignore[reportPrivateUsage] |
| 15 | +) |
6 | 16 |
|
7 | 17 | from typing_extensions import Annotated, NotRequired, Required, get_args, get_origin |
8 | 18 | from typing_extensions import Literal as ExtensionsLiteral |
@@ -44,12 +54,12 @@ def __init__(self, annotation: T) -> None: |
44 | 54 | unwrapped, metadata, wrappers = unwrap_annotation(annotation) |
45 | 55 | origin = get_origin(unwrapped) |
46 | 56 |
|
47 | | - args: tuple[Any, ...] = () if origin is abc.Callable else get_args(unwrapped) |
| 57 | + args: tuple[Any, ...] = () if origin is abc.Callable else get_args(unwrapped) # pyright: ignore |
48 | 58 |
|
49 | 59 | self.raw: Final[T] = annotation |
50 | 60 | self.annotation: Final = unwrapped |
51 | | - self.origin: Final = origin |
52 | | - self.fallback_origin: Final = origin or unwrapped |
| 61 | + self.origin: Final[Any] = origin |
| 62 | + self.fallback_origin: Final[Any] = origin or unwrapped |
53 | 63 | self.args: Final[tuple[Any, ...]] = args |
54 | 64 | self.metadata: Final = metadata |
55 | 65 | self._wrappers: Final = wrappers |
@@ -79,23 +89,23 @@ def repr_type(self) -> str: |
79 | 89 | """ |
80 | 90 | # Literal/Union both appear to have no name on some versions of python. |
81 | 91 | if self.is_literal: |
82 | | - name = "Literal" |
| 92 | + name: str = "Literal" |
83 | 93 | elif self.is_union: |
84 | 94 | name = "Union" |
85 | 95 | elif isinstance(self.annotation, (type, _SpecialForm)) or self.origin: |
86 | 96 | try: |
87 | | - name = self.annotation.__name__ # pyright: ignore[reportAttributeAccessIssue] |
| 97 | + name = str(self.annotation.__name__) # pyright: ignore |
88 | 98 | except AttributeError: |
89 | 99 | # Certain _SpecialForm items have no __name__ python 3.8. |
90 | | - name = self.annotation._name # pyright: ignore[reportAttributeAccessIssue] |
| 100 | + name = str(self.annotation._name) # pyright: ignore |
91 | 101 | else: |
92 | 102 | name = repr(self.annotation) |
93 | 103 |
|
94 | 104 | if self.origin: |
95 | 105 | inner_types = ", ".join(t.repr_type for t in self.inner_types) |
96 | 106 | name = f"{name}[{inner_types}]" |
97 | 107 |
|
98 | | - return str(name) |
| 108 | + return name |
99 | 109 |
|
100 | 110 | @property |
101 | 111 | def allows_none(self) -> bool: |
@@ -192,7 +202,7 @@ def is_variadic_tuple(self) -> bool: |
192 | 202 | Tuples like `tuple[int, ...]` represent a list-like unbounded sequence |
193 | 203 | of a single type T. |
194 | 204 | """ |
195 | | - return self.is_tuple and len(self.args) == 2 and self.args[1] == ... |
| 205 | + return self.is_tuple and len(self.args) == 2 and self.args[1] == ... # pyright: ignore |
196 | 206 |
|
197 | 207 | @property |
198 | 208 | def safe_generic_origin(self) -> Any: |
@@ -249,7 +259,7 @@ def is_subclass_of(self, typ: Any | tuple[Any, ...], /) -> bool: |
249 | 259 | """ |
250 | 260 | return isinstance(self.fallback_origin, type) and issubclass(self.fallback_origin, typ) |
251 | 261 |
|
252 | | - def strip_optional(self) -> TypeView: |
| 262 | + def strip_optional(self) -> TypeView[Any]: |
253 | 263 | if not self.is_optional: |
254 | 264 | return self |
255 | 265 |
|
|
0 commit comments