mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-10 14:01:55 +08:00
Bring _collections_abc closer to runtime definition (#6312)
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import sys
|
||||
from types import MappingProxyType
|
||||
from typing import (
|
||||
AbstractSet as Set,
|
||||
AsyncGenerator as AsyncGenerator,
|
||||
@@ -10,6 +12,7 @@ from typing import (
|
||||
Container as Container,
|
||||
Coroutine as Coroutine,
|
||||
Generator as Generator,
|
||||
Generic,
|
||||
Hashable as Hashable,
|
||||
ItemsView as ItemsView,
|
||||
Iterable as Iterable,
|
||||
@@ -23,8 +26,10 @@ from typing import (
|
||||
Reversible as Reversible,
|
||||
Sequence as Sequence,
|
||||
Sized as Sized,
|
||||
TypeVar,
|
||||
ValuesView as ValuesView,
|
||||
)
|
||||
from typing_extensions import final
|
||||
|
||||
__all__ = [
|
||||
"Awaitable",
|
||||
@@ -53,3 +58,21 @@ __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]
|
||||
|
||||
@@ -20,7 +20,7 @@ from _typeshed import (
|
||||
SupportsWrite,
|
||||
)
|
||||
from io import BufferedRandom, BufferedReader, BufferedWriter, FileIO, TextIOWrapper
|
||||
from types import CodeType, MappingProxyType, TracebackType
|
||||
from types import CodeType, TracebackType
|
||||
from typing import (
|
||||
IO,
|
||||
AbstractSet,
|
||||
@@ -32,10 +32,8 @@ from typing import (
|
||||
Callable,
|
||||
FrozenSet,
|
||||
Generic,
|
||||
ItemsView,
|
||||
Iterable,
|
||||
Iterator,
|
||||
KeysView,
|
||||
Mapping,
|
||||
MutableMapping,
|
||||
MutableSequence,
|
||||
@@ -56,12 +54,12 @@ from typing import (
|
||||
Type,
|
||||
TypeVar,
|
||||
Union,
|
||||
ValuesView,
|
||||
overload,
|
||||
)
|
||||
from typing_extensions import Literal, SupportsIndex, TypeGuard, final
|
||||
|
||||
from _ast import AST
|
||||
from _collections_abc import dict_items, dict_keys, dict_values
|
||||
|
||||
if sys.version_info >= (3, 9):
|
||||
from types import GenericAlias
|
||||
@@ -74,8 +72,6 @@ _T_co = TypeVar("_T_co", covariant=True)
|
||||
_T_contra = TypeVar("_T_contra", contravariant=True)
|
||||
_KT = TypeVar("_KT")
|
||||
_VT = TypeVar("_VT")
|
||||
_KT_co = TypeVar("_KT_co", covariant=True) # Key type covariant containers.
|
||||
_VT_co = TypeVar("_VT_co", covariant=True) # Value type covariant containers.
|
||||
_S = TypeVar("_S")
|
||||
_T1 = TypeVar("_T1")
|
||||
_T2 = TypeVar("_T2")
|
||||
@@ -809,18 +805,6 @@ class list(MutableSequence[_T], Generic[_T]):
|
||||
if sys.version_info >= (3, 9):
|
||||
def __class_getitem__(cls, __item: Any) -> GenericAlias: ...
|
||||
|
||||
class _dict_keys(KeysView[_KT_co], Generic[_KT_co, _VT_co]):
|
||||
if sys.version_info >= (3, 10):
|
||||
mapping: MappingProxyType[_KT_co, _VT_co]
|
||||
|
||||
class _dict_values(ValuesView[_VT_co], Generic[_KT_co, _VT_co]):
|
||||
if sys.version_info >= (3, 10):
|
||||
mapping: MappingProxyType[_KT_co, _VT_co]
|
||||
|
||||
class _dict_items(ItemsView[_KT_co, _VT_co], Generic[_KT_co, _VT_co]):
|
||||
if sys.version_info >= (3, 10):
|
||||
mapping: MappingProxyType[_KT_co, _VT_co]
|
||||
|
||||
class dict(MutableMapping[_KT, _VT], Generic[_KT, _VT]):
|
||||
@overload
|
||||
def __init__(self: dict[_KT, _VT]) -> None: ...
|
||||
@@ -845,9 +829,9 @@ class dict(MutableMapping[_KT, _VT], Generic[_KT, _VT]):
|
||||
def update(self, __m: Iterable[tuple[_KT, _VT]], **kwargs: _VT) -> None: ...
|
||||
@overload
|
||||
def update(self, **kwargs: _VT) -> None: ...
|
||||
def keys(self) -> _dict_keys[_KT, _VT]: ...
|
||||
def values(self) -> _dict_values[_KT, _VT]: ...
|
||||
def items(self) -> _dict_items[_KT, _VT]: ...
|
||||
def keys(self) -> dict_keys[_KT, _VT]: ...
|
||||
def values(self) -> dict_values[_KT, _VT]: ...
|
||||
def items(self) -> dict_items[_KT, _VT]: ...
|
||||
@classmethod
|
||||
@overload
|
||||
def fromkeys(cls, __iterable: Iterable[_T], __value: None = ...) -> dict[_T, Any | None]: ...
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import sys
|
||||
from _typeshed import Self
|
||||
from builtins import _dict_items, _dict_keys, _dict_values
|
||||
from typing import Any, Dict, Generic, NoReturn, Tuple, Type, TypeVar, overload
|
||||
from typing_extensions import final
|
||||
|
||||
from _collections_abc import dict_items, dict_keys, dict_values
|
||||
|
||||
if sys.version_info >= (3, 10):
|
||||
from typing import Callable, Iterable, Iterator, Mapping, MutableMapping, MutableSequence, Reversible, Sequence
|
||||
else:
|
||||
@@ -242,15 +243,15 @@ class Counter(Dict[_T, int], Generic[_T]):
|
||||
def __ior__(self, other: Counter[_T]) -> Counter[_T]: ... # type: ignore
|
||||
|
||||
@final
|
||||
class _OrderedDictKeysView(_dict_keys[_KT_co, _VT_co], Reversible[_KT_co]):
|
||||
class _OrderedDictKeysView(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]]):
|
||||
class _OrderedDictItemsView(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]):
|
||||
class _OrderedDictValuesView(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]):
|
||||
|
||||
Reference in New Issue
Block a user