|
1 | 1 | # pyright: reportIncompatibleMethodOverride=false |
2 | 2 | import abc |
3 | 3 | import typing |
4 | | -from typing import Any, Generator |
5 | 4 |
|
6 | 5 | from . import types |
7 | 6 |
|
|
15 | 14 | #: A type alias for a dictionary with keys of type KT and values of type VT. |
16 | 15 | DT = types.Dict[KT, VT] |
17 | 16 | #: A type alias for the casted type of a dictionary key. |
18 | | -KT_cast = types.Optional[types.Callable[[Any], KT]] |
| 17 | +KT_cast = types.Optional[types.Callable[..., KT]] |
19 | 18 | #: A type alias for the casted type of a dictionary value. |
20 | | -VT_cast = types.Optional[types.Callable[[Any], VT]] |
| 19 | +VT_cast = types.Optional[types.Callable[..., VT]] |
21 | 20 | #: A type alias for the hashable values of the `UniqueList` |
22 | 21 | HT = types.TypeVar('HT', bound=types.Hashable) |
23 | 22 |
|
24 | 23 | # Using types.Union instead of | since Python 3.7 doesn't fully support it |
25 | 24 | DictUpdateArgs = types.Union[ |
26 | | - types.Mapping[types.Any, types.Any], |
27 | | - types.Iterable[ |
28 | | - types.Union[types.Tuple[Any, Any], types.Mapping[types.Any, types.Any]] |
29 | | - ], |
| 25 | + types.Mapping[KT, VT], |
| 26 | + types.Iterable[types.Tuple[KT, VT]], |
| 27 | + types.Iterable[types.Mapping[KT, VT]], |
30 | 28 | '_typeshed.SupportsKeysAndGetItem[KT, VT]', |
31 | 29 | ] |
32 | 30 |
|
@@ -56,7 +54,7 @@ def update( |
56 | 54 | for key, value in kwargs.items(): |
57 | 55 | self[key] = value |
58 | 56 |
|
59 | | - def __setitem__(self, key: Any, value: Any) -> None: |
| 57 | + def __setitem__(self, key: types.Any, value: types.Any) -> None: |
60 | 58 | if self._key_cast is not None: |
61 | 59 | key = self._key_cast(key) |
62 | 60 |
|
@@ -168,14 +166,16 @@ def __getitem__(self, key: types.Any) -> VT: |
168 | 166 |
|
169 | 167 | return value |
170 | 168 |
|
171 | | - def items(self) -> Generator[tuple[KT, VT], None, None]: # type: ignore |
| 169 | + def items( # type: ignore |
| 170 | + self, |
| 171 | + ) -> types.Generator[types.Tuple[KT, VT], None, None]: |
172 | 172 | if self._value_cast is None: |
173 | 173 | yield from super().items() |
174 | 174 | else: |
175 | 175 | for key, value in super().items(): |
176 | 176 | yield key, self._value_cast(value) |
177 | 177 |
|
178 | | - def values(self) -> Generator[VT, None, None]: # type: ignore |
| 178 | + def values(self) -> types.Generator[VT, None, None]: # type: ignore |
179 | 179 | if self._value_cast is None: |
180 | 180 | yield from super().values() |
181 | 181 | else: |
|
0 commit comments