8000 Fix for dict_keys being in _collections.abc by mattdavis90 · Pull Request #6888 · python/typeshed · GitHub
[go: up one dir, main page]

Skip to content

Fix for dict_keys being in _collections.abc #6888

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 0 additions & 23 deletions stdlib/_collections_abc.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import sys
from types import MappingProxyType
from typing import (
AbstractSet as Set,
AsyncGenerator as AsyncGenerator,
Expand All @@ -12,7 +10,6 @@ from typing import (
Container as Container,
Coroutine as Coroutine,
Generator as Generator,
Generic,
Hashable as Hashable,
ItemsView as ItemsView,
Iterable as Iterable,
Expand All @@ -26,10 +23,8 @@ from typing import (
Reversible as Reversible,
Sequence as Sequence,
Sized as Sized,
TypeVar,
ValuesView as ValuesView,
)
from typing_extensions import final

__all__ = [
"Awaitable",
Expand Down Expand Up @@ -58,21 +53,3 @@ __all__ = [
"MutableSequence",
"ByteString",
]

_KT_co = TypeVar("_KT_co", covariant=True) # Key type covariant containers.
_VT_co = TypeVar("_VT_co", covariant=True) # Value type covariant containers.

@final
class dict_keys(KeysView[_KT_co], Generic[_KT_co, _VT_co]): # undocumented
if sys.version_info >= (3, 10):
mapping: MappingProxyType[_KT_co, _VT_co]

@final
class dict_values(ValuesView[_VT_co], Generic[_KT_co, _VT_co]): # undocumented
if sys.version_info >= (3, 10):
mapping: MappingProxyType[_KT_co, _VT_co]

@final
class dict_items(ItemsView[_KT_co, _VT_co], Generic[_KT_co, _VT_co]): # undocumented
if sys.version_info >= (3, 10):
mapping: MappingProxyType[_KT_co, _VT_co]
10 changes: 6 additions & 4 deletions stdlib/builtins.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import sys
import types
from _ast import AST
from _collections_abc import dict_items, dict_keys, dict_values
from _typeshed import (
OpenBinaryMode,
OpenBinaryModeReading,
Expand Down Expand Up @@ -32,8 +31,10 @@ from typing import (
ByteString,
Callable,
Generic,
ItemsView,
Iterable,
Iterator,
KeysView,
Mapping,
MutableMapping,
MutableSequence,
Expand All @@ -51,6 +52,7 @@ from typing import (
SupportsRound,
TypeVar,
Union,
ValuesView,
overload,
)
from typing_extensions import Literal, SupportsIndex, TypeGuard, final
Expand Down Expand Up @@ -847,9 +849,9 @@ class dict(MutableMapping[_KT, _VT], Generic[_KT, _VT]):
def __init__(self: dict[str, str], __iterable: Iterable[list[str]]) -> None: ...
def __new__(cls: type[Self], *args: Any, **kwargs: Any) -> Self: ...
def copy(self) -> dict[_KT, _VT]: ...
def keys(self) -> dict_keys[_KT, _VT]: ...
def values(self) -> dict_values[_KT, _VT]: ...
def items(self) -> dict_items[_KT, _VT]: ...
def keys(self) -> KeysView[_KT]: ...
def values(self) -> ValuesView[_VT]: ...
def items(self) -> ItemsView[_KT, _VT]: ...
# Signature of `dict.fromkeys` should be kept identical to `fromkeys` methods of `OrderedDict`/`ChainMap`/`UserDict` in `collections`
# TODO: the true signature of `dict.fromkeys` is not expressible in the current type system.
# See #3800 & https://github.com/python/typing/issues/548#issuecomment-683336963.
Expand Down
9 changes: 4 additions & 5 deletions stdlib/collections/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import sys
from _collections_abc import dict_items, dict_keys, dict_values
from _typeshed import Self, SupportsKeysAndGetItem, SupportsRichComparison, SupportsRichComparisonT
from typing import Any, Generic, NoReturn, TypeVar, overload
from typing_extensions import SupportsIndex, final
Expand Down Expand Up @@ -256,23 +255,23 @@ class Counter(dict[_T, int], Generic[_T]):
def total(self) -> int: ...

@final
class _OrderedDictKeysView(dict_keys[_KT_co, _VT_co], Reversible[_KT_co]): # type: ignore[misc]
class _OrderedDictKeysView(KeysView[_KT_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 _OrderedDictItemsView(ItemsView[_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 _OrderedDictValuesView(ValuesView[_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]):
def popitem(self, last: bool = ...) -> tuple[_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 keys(self) -> _OrderedDictKeysView[_KT]: ...
def items(self) -> _OrderedDictItemsView[_KT, _VT]: ...
def values(self) -> _OrderedDictValuesView[_KT, _VT]: ...
# `fromkeys` is actually inherited from `dict` at runtime, so the signature should be kept in line with `dict.fromkeys`.
Expand Down
8 changes: 7 additions & 1 deletion stdlib/typing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import collections # Needed by aliases like DefaultDict, see mypy issue 2986
import sys
from _typeshed import Self, SupportsKeysAndGetItem
from abc import ABCMeta, abstractmethod
from types import BuiltinFunctionType, CodeType, FrameType, FunctionType, MethodType, ModuleType, TracebackType
from types import BuiltinFunctionType, CodeType, FrameType, FunctionType, MappingProxyType, MethodType, ModuleType, TracebackType
from typing_extensions import Literal as _Literal, ParamSpec as _ParamSpec, final as _final

if sys.version_info >= (3, 7):
Expand Down Expand Up @@ -414,6 +414,8 @@ class ItemsView(MappingView, AbstractSet[Tuple[_KT_co, _VT_co]], Generic[_KT_co,
def __rsub__(self, o: Iterable[_T]) -> set[_T]: ...
def __xor__(self, o: Iterable[_T]) -> set[tuple[_KT_co, _VT_co] | _T]: ...
def __rxor__(self, o: Iterable[_T]) -> set[tuple[_KT_co, _VT_co] | _T]: ...
if sys.version_info >= (3, 10):
mapping: MappingProxyType[_KT_co, _VT_co]

class KeysView(MappingView, AbstractSet[_KT_co], Generic[_KT_co]):
def __init__(self, mapping: Mapping[_KT_co, Any]) -> None: ... # undocumented
Expand All @@ -429,13 +431,17 @@ class KeysView(MappingView, AbstractSet[_KT_co], Generic[_KT_co]):
def __rsub__(self, o: Iterable[_T]) -> set[_T]: ...
def __xor__(self, o: Iterable[_T]) -> set[_KT_co | _T]: ...
def __rxor__(self, o: Iterable[_T]) -> set[_KT_co | _T]: ...
if sys.version_info >= (3, 10):
mapping: MappingProxyType[_KT_co, _VT_co]

class ValuesView(MappingView, Iterable[_VT_co], Generic[_VT_co]):
def __init__(self, mapping: Mapping[Any, _VT_co]) -> None: ... # undocumented
def __contains__(self, o: object) -> bool: ...
def __iter__(self) -> Iterator[_VT_co]: ...
if sys.version_info >= (3, 8):
def __reversed__(self) -> Iterator[_VT_co]: ...
if sys.version_info >= (3, 10):
mapping: MappingProxyType[_KT_co, _VT_co]

@runtime_checkable
class ContextManager(Protocol[_T_co]):
Expand Down
0