|
1 |
| -from __future__ import annotations |
2 |
| - |
3 | 1 | import abc
|
4 | 2 | import typing
|
5 | 3 | from typing import Any, Generator
|
|
9 | 7 | if typing.TYPE_CHECKING:
|
10 | 8 | import _typeshed # noqa: F401
|
11 | 9 |
|
| 10 | +#: A type alias for a type that can be used as a key in a dictionary. |
12 | 11 | KT = types.TypeVar('KT')
|
| 12 | +#: A type alias for a type that can be used as a value in a dictionary. |
13 | 13 | VT = types.TypeVar('VT')
|
| 14 | +#: A type alias for a dictionary with keys of type KT and values of type VT. |
14 | 15 | DT = types.Dict[KT, VT]
|
| 16 | +#: A type alias for the casted type of a dictionary key. |
15 | 17 | KT_cast = types.Optional[types.Callable[[Any], KT]]
|
| 18 | +#: A type alias for the casted type of a dictionary value. |
16 | 19 | VT_cast = types.Optional[types.Callable[[Any], VT]]
|
| 20 | +#: A type alias for the hashable values of the `UniqueList` |
17 | 21 | HT = types.TypeVar('HT', bound=types.Hashable)
|
18 | 22 |
|
19 | 23 | # Using types.Union instead of | since Python 3.7 doesn't fully support it
|
@@ -61,7 +65,7 @@ class CastedDict(CastedDictBase[KT, VT]):
|
61 | 65 | Note that you can specify the types for mypy and type hinting with:
|
62 | 66 | CastedDict[int, int](int, int)
|
63 | 67 |
|
64 |
| - >>> d = CastedDict(int, int) |
| 68 | + >>> d: CastedDict[int, int] = CastedDict(int, int) |
65 | 69 | >>> d[1] = 2
|
66 | 70 | >>> d['3'] = '4'
|
67 | 71 | >>> d.update({'5': '6'})
|
@@ -105,7 +109,7 @@ class LazyCastedDict(CastedDictBase[KT, VT]):
|
105 | 109 | Note that you can specify the types for mypy and type hinting with:
|
106 | 110 | LazyCastedDict[int, int](int, int)
|
107 | 111 |
|
108 |
| - >>> d = LazyCastedDict(int, int) |
| 112 | + >>> d: LazyCastedDict[int, int] = LazyCastedDict(int, int) |
109 | 113 | >>> d[1] = 2
|
110 | 114 | >>> d['3'] = '4'
|
111 | 115 | >>> d.update({'5': '6'})
|
@@ -159,7 +163,9 @@ def __getitem__(self, key: Any) -> VT:
|
159 | 163 |
|
160 | 164 | return value
|
161 | 165 |
|
162 |
| - def items(self) -> Generator[tuple[KT, VT], None, None]: # type: ignore |
| 166 | + def items( # type: ignore |
| 167 | + self, |
| 168 | + ) -> Generator[types.Tuple[KT, VT], None, None]: |
163 | 169 | if self._value_cast is None:
|
164 | 170 | yield from super().items()
|
165 | 171 | else:
|
@@ -208,7 +214,7 @@ class UniqueList(types.List[HT]):
|
208 | 214 | ValueError: Duplicate value: 4
|
209 | 215 | '''
|
210 | 216 |
|
211 |
| - _set: set[HT] |
| 217 | + _set: types.Set[HT] |
212 | 218 |
|
213 | 219 | def __init__(
|
214 | 220 | self,
|
|
0 commit comments