mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-09 13:34:58 +08:00
Improve classes returned from OrderedDict.{keys(), items(), values()} (#8552)
This commit is contained in:
@@ -8,7 +8,19 @@ if sys.version_info >= (3, 9):
|
||||
from types import GenericAlias
|
||||
|
||||
if sys.version_info >= (3, 10):
|
||||
from collections.abc import Callable, Iterable, Iterator, Mapping, MutableMapping, MutableSequence, Reversible, Sequence
|
||||
from collections.abc import (
|
||||
Callable,
|
||||
ItemsView,
|
||||
Iterable,
|
||||
Iterator,
|
||||
KeysView,
|
||||
Mapping,
|
||||
MutableMapping,
|
||||
MutableSequence,
|
||||
Reversible,
|
||||
Sequence,
|
||||
ValuesView,
|
||||
)
|
||||
else:
|
||||
from _collections_abc import *
|
||||
|
||||
@@ -301,16 +313,30 @@ class Counter(dict[_T, int], Generic[_T]):
|
||||
def __ge__(self, other: Counter[Any]) -> bool: ...
|
||||
def __gt__(self, other: Counter[Any]) -> bool: ...
|
||||
|
||||
# The pure-Python implementations of the "views" classes
|
||||
# These are exposed at runtime in `collections/__init__.py`
|
||||
class _OrderedDictKeysView(KeysView[_KT_co], Reversible[_KT_co]):
|
||||
def __reversed__(self) -> Iterator[_KT_co]: ...
|
||||
|
||||
class _OrderedDictItemsView(ItemsView[_KT_co, _VT_co], Reversible[tuple[_KT_co, _VT_co]]):
|
||||
def __reversed__(self) -> Iterator[tuple[_KT_co, _VT_co]]: ...
|
||||
|
||||
class _OrderedDictValuesView(ValuesView[_VT_co], Reversible[_VT_co]):
|
||||
def __reversed__(self) -> Iterator[_VT_co]: ...
|
||||
|
||||
# The C implementations of the "views" classes
|
||||
# (At runtime, these are called `odict_keys`, `odict_items` and `odict_values`,
|
||||
# but they are not exposed anywhere)
|
||||
@final
|
||||
class _OrderedDictKeysView(dict_keys[_KT_co, _VT_co], Reversible[_KT_co]): # type: ignore[misc]
|
||||
class _odict_keys(dict_keys[_KT_co, _VT_co], Reversible[_KT_co]): # type: ignore[misc]
|
||||
def __reversed__(self) -> Iterator[_KT_co]: ...
|
||||
|
||||
@final
|
||||
class _OrderedDictItemsView(dict_items[_KT_co, _VT_co], Reversible[tuple[_KT_co, _VT_co]]): # type: ignore[misc]
|
||||
class _odict_items(dict_items[_KT_co, _VT_co], Reversible[tuple[_KT_co, _VT_co]]): # type: ignore[misc]
|
||||
def __reversed__(self) -> Iterator[tuple[_KT_co, _VT_co]]: ...
|
||||
|
||||
@final
|
||||
class _OrderedDictValuesView(dict_values[_KT_co, _VT_co], Reversible[_VT_co], Generic[_KT_co, _VT_co]): # type: ignore[misc]
|
||||
class _odict_values(dict_values[_KT_co, _VT_co], Reversible[_VT_co], Generic[_KT_co, _VT_co]): # type: ignore[misc]
|
||||
def __reversed__(self) -> Iterator[_VT_co]: ...
|
||||
|
||||
class OrderedDict(dict[_KT, _VT], Reversible[_KT], Generic[_KT, _VT]):
|
||||
@@ -318,9 +344,9 @@ class OrderedDict(dict[_KT, _VT], Reversible[_KT], Generic[_KT, _VT]):
|
||||
def move_to_end(self, key: _KT, last: bool = ...) -> None: ...
|
||||
def copy(self: Self) -> Self: ...
|
||||
def __reversed__(self) -> Iterator[_KT]: ...
|
||||
def keys(self) -> _OrderedDictKeysView[_KT, _VT]: ...
|
||||
def items(self) -> _OrderedDictItemsView[_KT, _VT]: ...
|
||||
def values(self) -> _OrderedDictValuesView[_KT, _VT]: ...
|
||||
def keys(self) -> _odict_keys[_KT, _VT]: ...
|
||||
def items(self) -> _odict_items[_KT, _VT]: ...
|
||||
def values(self) -> _odict_values[_KT, _VT]: ...
|
||||
# The signature of OrderedDict.fromkeys should be kept in line with `dict.fromkeys`, modulo positional-only differences.
|
||||
# Like dict.fromkeys, its true signature is not expressible in the current type system.
|
||||
# See #3800 & https://github.com/python/typing/issues/548#issuecomment-683336963.
|
||||
|
||||
Reference in New Issue
Block a user