|
1 | 1 | import sys
|
2 | 2 | from _typeshed import Self
|
| 3 | +from builtins import _dict_items, _dict_keys, _dict_values |
3 | 4 | from typing import Any, Dict, Generic, NoReturn, Tuple, Type, TypeVar, overload
|
4 | 5 |
|
5 | 6 | if sys.version_info >= (3, 10):
|
6 |
| - from typing import ( |
7 |
| - Callable, |
8 |
| - ItemsView, |
9 |
| - Iterable, |
10 |
| - Iterator, |
11 |
| - KeysView, |
12 |
| - Mapping, |
13 |
| - MutableMapping, |
14 |
| - MutableSequence, |
15 |
| - Reversible, |
16 |
| - Sequence, |
17 |
| - ValuesView, |
18 |
| - ) |
| 7 | + from typing import Callable, Iterable, Iterator, Mapping, MutableMapping, MutableSequence, Reversible, Sequence |
19 | 8 | else:
|
20 | 9 | from _collections_abc import *
|
21 | 10 |
|
22 | 11 | _S = TypeVar("_S")
|
23 | 12 | _T = TypeVar("_T")
|
24 | 13 | _KT = TypeVar("_KT")
|
25 | 14 | _VT = TypeVar("_VT")
|
| 15 | +_KT_co = TypeVar("_KT_co", covariant=True) |
| 16 | +_VT_co = TypeVar("_VT_co", covariant=True) |
26 | 17 |
|
27 | 18 | # namedtuple is special-cased in the type checker; the initializer is ignored.
|
28 | 19 | if sys.version_info >= (3, 7):
|
@@ -247,23 +238,25 @@ class Counter(Dict[_T, int], Generic[_T]):
|
247 | 238 | def __iand__(self, other: Counter[_T]) -> Counter[_T]: ...
|
248 | 239 | def __ior__(self, other: Counter[_T]) -> Counter[_T]: ... # type: ignore
|
249 | 240 |
|
250 |
| -class _OrderedDictKeysView(KeysView[_KT], Reversible[_KT]): |
251 |
| - def __reversed__(self) -> Iterator[_KT]: ... |
| 241 | +class _OrderedDictKeysView(_dict_keys[_KT_co, _VT_co], Reversible[_KT_co]): |
| 242 | + def __reversed__(self) -> Iterator[_KT_co]: ... |
252 | 243 |
|
253 |
| -class _OrderedDictItemsView(ItemsView[_KT, _VT], Reversible[Tuple[_KT, _VT]]): |
254 |
| - def __reversed__(self) -> Iterator[Tuple[_KT, _VT]]: ... |
| 244 | +class _OrderedDictItemsView(_dict_items[_KT_co, _VT_co], Reversible[Tuple[_KT_co, _VT_co]]): |
| 245 | + def __reversed__(self) -> Iterator[Tuple[_KT_co, _VT_co]]: ... |
255 | 246 |
|
256 |
| -class _OrderedDictValuesView(ValuesView[_VT], Reversible[_VT]): |
257 |
| - def __reversed__(self) -> Iterator[_VT]: ... |
| 247 | +# The generics are the wrong way around because of a mypy limitation |
| 248 | +# https://github.com/python/mypy/issues/11138 |
| 249 | +class _OrderedDictValuesView(_dict_values[_VT_co, _KT_co], Reversible[_VT_co], Generic[_VT_co, _KT_co]): |
| 250 | + def __reversed__(self) -> Iterator[_VT_co]: ... |
258 | 251 |
|
259 | 252 | class OrderedDict(Dict[_KT, _VT], Reversible[_KT], Generic[_KT, _VT]):
|
260 | 253 | def popitem(self, last: bool = ...) -> Tuple[_KT, _VT]: ...
|
261 | 254 | def move_to_end(self, key: _KT, last: bool = ...) -> None: ...
|
262 | 255 | def copy(self: _S) -> _S: ...
|
263 | 256 | def __reversed__(self) -> Iterator[_KT]: ...
|
264 |
| - def keys(self) -> _OrderedDictKeysView[_KT]: ... |
| 257 | + def keys(self) -> _OrderedDictKeysView[_KT, _VT]: ... |
265 | 258 | def items(self) -> _OrderedDictItemsView[_KT, _VT]: ...
|
266 |
| - def values(self) -> _OrderedDictValuesView[_VT]: ... |
| 259 | + def values(self) -> _OrderedDictValuesView[_VT, _KT]: ... |
267 | 260 |
|
268 | 261 | class defaultdict(Dict[_KT, _VT], Generic[_KT, _VT]):
|
269 | 262 | default_factory: Callable[[], _VT] | None
|
|
0 commit comments