|
|
@@ -1,6 +1,6 @@ |
|
|
import sys |
|
|
from _collections_abc import dict_items, dict_keys, dict_values |
|
|
from _typeshed import Self, SupportsKeysAndGetItem, SupportsRichComparison, SupportsRichComparisonT |
|
|
from _typeshed import IterableOrSupportsIntGetItem, Self, SupportsKeysAndGetItem, SupportsRichComparison, SupportsRichComparisonT |
|
|
from typing import Any, Generic, NoReturn, TypeVar, overload |
|
|
from typing_extensions import SupportsIndex, final |
|
|
|
|
Expand All
|
@@ -11,7 +11,6 @@ if sys.version_info >= (3, 10): |
|
|
from collections.abc import ( |
|
|
Callable, |
|
|
ItemsView, |
|
|
Iterable, |
|
|
Iterator, |
|
|
KeysView, |
|
|
Mapping, |
|
Expand All
|
@@ -38,11 +37,11 @@ _VT_co = TypeVar("_VT_co", covariant=True) |
|
|
# namedtuple is special-cased in the type checker; the initializer is ignored. |
|
|
def namedtuple( |
|
|
typename: str, |
|
|
field_names: str | Iterable[str], |
|
|
field_names: str | IterableOrSupportsIntGetItem[str], |
|
|
*, |
|
|
rename: bool = ..., |
|
|
module: str | None = ..., |
|
|
defaults: Iterable[Any] | None = ..., |
|
|
defaults: IterableOrSupportsIntGetItem[Any] | None = ..., |
|
|
) -> type[tuple[Any, ...]]: ... |
|
|
|
|
|
class UserDict(MutableMapping[_KT, _VT], Generic[_KT, _VT]): |
|
Expand All
|
@@ -57,11 +56,11 @@ class UserDict(MutableMapping[_KT, _VT], Generic[_KT, _VT]): |
|
|
@overload |
|
|
def __init__(self: UserDict[str, _VT], __dict: SupportsKeysAndGetItem[str, _VT], **kwargs: _VT) -> None: ... |
|
|
@overload |
|
|
def __init__(self, __iterable: Iterable[tuple[_KT, _VT]]) -> None: ... |
|
|
def __init__(self, __iterable: IterableOrSupportsIntGetItem[tuple[_KT, _VT]]) -> None: ... |
|
|
@overload |
|
|
def __init__(self: UserDict[str, _VT], __iterable: Iterable[tuple[str, _VT]], **kwargs: _VT) -> None: ... |
|
|
def __init__(self: UserDict[str, _VT], __iterable: IterableOrSupportsIntGetItem[tuple[str, _VT]], **kwargs: _VT) -> None: ... |
|
|
@overload |
|
|
def __init__(self: UserDict[str, str], __iterable: Iterable[list[str]]) -> None: ... |
|
|
def __init__(self: UserDict[str, str], __iterable: IterableOrSupportsIntGetItem[list[str]]) -> None: ... |
|
|
def __len__(self) -> int: ... |
|
|
def __getitem__(self, key: _KT) -> _VT: ... |
|
|
def __setitem__(self, key: _KT, item: _VT) -> None: ... |
|
Expand All
|
@@ -76,25 +75,25 @@ class UserDict(MutableMapping[_KT, _VT], Generic[_KT, _VT]): |
|
|
# See #3800 & https://github.com/python/typing/issues/548#issuecomment-683336963. |
|
|
@classmethod |
|
|
@overload |
|
|
def fromkeys(cls, iterable: Iterable[_T], value: None = ...) -> UserDict[_T, Any | None]: ... |
|
|
def fromkeys(cls, iterable: IterableOrSupportsIntGetItem[_T], value: None = ...) -> UserDict[_T, Any | None]: ... |
|
|
@classmethod |
|
|
@overload |
|
|
def fromkeys(cls, iterable: Iterable[_T], value: _S) -> UserDict[_T, _S]: ... |
|
|
def fromkeys(cls, iterable: IterableOrSupportsIntGetItem[_T], value: _S) -> UserDict[_T, _S]: ... |
|
|
if sys.version_info >= (3, 9): |
|
|
def __or__(self, other: UserDict[_T1, _T2] | dict[_T1, _T2]) -> UserDict[_KT | _T1, _VT | _T2]: ... |
|
|
def __ror__(self, other: UserDict[_T1, _T2] | dict[_T1, _T2]) -> UserDict[_KT | _T1, _VT | _T2]: ... # type: ignore[misc] |
|
|
# UserDict.__ior__ should be kept roughly in line with MutableMapping.update() |
|
|
@overload # type: ignore[misc] |
|
|
def __ior__(self: Self, other: SupportsKeysAndGetItem[_KT, _VT]) -> Self: ... |
|
|
@overload |
|
|
def __ior__(self: Self, other: Iterable[tuple[_KT, _VT]]) -> Self: ... |
|
|
def __ior__(self: Self, other: IterableOrSupportsIntGetItem[tuple[_KT, _VT]]) -> Self: ... |
|
|
|
|
|
class UserList(MutableSequence[_T]): |
|
|
data: list[_T] |
|
|
@overload |
|
|
def __init__(self, initlist: None = ...) -> None: ... |
|
|
@overload |
|
|
def __init__(self, initlist: Iterable[_T]) -> None: ... |
|
|
def __init__(self, initlist: IterableOrSupportsIntGetItem[_T]) -> None: ... |
|
|
def __lt__(self, other: list[_T] | UserList[_T]) -> bool: ... |
|
|
def __le__(self, other: list[_T] | UserList[_T]) -> bool: ... |
|
|
def __gt__(self, other: list[_T] | UserList[_T]) -> bool: ... |
|
Expand All
|
@@ -109,11 +108,11 @@ class UserList(MutableSequence[_T]): |
|
|
@overload |
|
|
def __setitem__(self, i: SupportsIndex, item: _T) -> None: ... |
|
|
@overload |
|
|
def __setitem__(self, i: slice, item: Iterable[_T]) -> None: ... |
|
|
def __setitem__(self, i: slice, item: IterableOrSupportsIntGetItem[_T]) -> None: ... |
|
|
def __delitem__(self, i: SupportsIndex | slice) -> None: ... |
|
|
def __add__(self: Self, other: Iterable[_T]) -> Self: ... |
|
|
def __radd__(self: Self, other: Iterable[_T]) -> Self: ... |
|
|
def __iadd__(self: Self, other: Iterable[_T]) -> Self: ... |
|
|
def __add__(self: Self, other: IterableOrSupportsIntGetItem[_T]) -> Self: ... |
|
|
def __radd__(self: Self, other: IterableOrSupportsIntGetItem[_T]) -> Self: ... |
|
|
def __iadd__(self: Self, other: IterableOrSupportsIntGetItem[_T]) -> Self: ... |
|
|
def __mul__(self: Self, n: int) -> Self: ... |
|
|
def __rmul__(self: Self, n: int) -> Self: ... |
|
|
def __imul__(self: Self, n: int) -> Self: ... |
|
Expand All
|
@@ -131,7 +130,7 @@ class UserList(MutableSequence[_T]): |
|
|
def sort(self: UserList[SupportsRichComparisonT], *, key: None = ..., reverse: bool = ...) -> None: ... |
|
|
@overload |
|
|
def sort(self, *, key: Callable[[_T], SupportsRichComparison], reverse: bool = ...) -> None: ... |
|
|
def extend(self, other: Iterable[_T]) -> None: ... |
|
|
def extend(self, other: IterableOrSupportsIntGetItem[_T]) -> None: ... |
|
|
|
|
|
class UserString(Sequence[UserString]): |
|
|
data: str |
|
Expand Down
Expand Up
|
@@ -187,7 +186,7 @@ class UserString(Sequence[UserString]): |
|
|
def istitle(self) -> bool: ... |
|
|
def isupper(self) -> bool: ... |
|
|
def isascii(self) -> bool: ... |
|
|
def join(self, seq: Iterable[str]) -> str: ... |
|
|
def join(self, seq: IterableOrSupportsIntGetItem[str]) -> str: ... |
|
|
def ljust(self: Self, width: int, *args: Any) -> Self: ... |
|
|
def lower(self: Self) -> Self: ... |
|
|
def lstrip(self: Self, chars: str | None = ...) -> Self: ... |
|
Expand Down
Expand Up
|
@@ -225,13 +224,13 @@ class deque(MutableSequence[_T], Generic[_T]): |
|
|
@overload |
|
|
def __init__(self, *, maxlen: int | None = ...) -> None: ... |
|
|
@overload |
|
|
def __init__(self, iterable: Iterable[_T], maxlen: int | None = ...) -> None: ... |
|
|
def __init__(self, iterable: IterableOrSupportsIntGetItem[_T], maxlen: int | None = ...) -> None: ... |
|
|
def append(self, __x: _T) -> None: ... |
|
|
def appendleft(self, __x: _T) -> None: ... |
|
|
def copy(self: Self) -> Self: ... |
|
|
def count(self, __x: _T) -> int: ... |
|
|
def extend(self, __iterable: Iterable[_T]) -> None: ... |
|
|
def extendleft(self, __iterable: Iterable[_T]) -> None: ... |
|
|
def extend(self, __iterable: IterableOrSupportsIntGetItem[_T]) -> None: ... |
|
|
def extendleft(self, __iterable: IterableOrSupportsIntGetItem[_T]) -> None: ... |
|
|
def insert(self, __i: int, __x: _T) -> None: ... |
|
|
def index(self, __x: _T, __start: int = ..., __stop: int = ...) -> int: ... |
|
|
def pop(self) -> _T: ... # type: ignore[override] |
|
Expand All
|
@@ -246,7 +245,7 @@ class deque(MutableSequence[_T], Generic[_T]): |
|
|
def __delitem__(self, __i: SupportsIndex) -> None: ... # type: ignore[override] |
|
|
def __contains__(self, __o: object) -> bool: ... |
|
|
def __reduce__(self: Self) -> tuple[type[Self], tuple[()], None, Iterator[_T]]: ... |
|
|
def __iadd__(self: Self, __iterable: Iterable[_T]) -> Self: ... |
|
|
def __iadd__(self: Self, __iterable: IterableOrSupportsIntGetItem[_T]) -> Self: ... |
|
|
def __add__(self: Self, __other: Self) -> Self: ... |
|
|
def __mul__(self: Self, __other: int) -> Self: ... |
|
|
def __imul__(self: Self, __other: int) -> Self: ... |
|
Expand All
|
@@ -265,7 +264,7 @@ class Counter(dict[_T, int], Generic[_T]): |
|
|
@overload |
|
|
def __init__(self, __mapping: SupportsKeysAndGetItem[_T, int]) -> None: ... |
|
|
@overload |
|
|
def __init__(self, __iterable: Iterable[_T]) -> None: ... |
|
|
def __init__(self, __iterable: IterableOrSupportsIntGetItem[_T]) -> None: ... |
|
|
def copy(self: Self) -> Self: ... |
|
|
def elements(self) -> Iterator[_T]: ... |
|
|
def most_common(self, n: int | None = ...) -> list[tuple[_T, int]]: ... |
|
Expand All
|
@@ -276,17 +275,17 @@ class Counter(dict[_T, int], Generic[_T]): |
|
|
@overload |
|
|
def subtract(self, __mapping: Mapping[_T, int]) -> None: ... |
|
|
@overload |
|
|
def subtract(self, __iterable: Iterable[_T]) -> None: ... |
|
|
def subtract(self, __iterable: IterableOrSupportsIntGetItem[_T]) -> None: ... |
|
|
# Unlike dict.update(), use Mapping instead of SupportsKeysAndGetItem for the first overload |
|
|
# (source code does an `isinstance(other, Mapping)` check) |
|
|
# |
|
|
# The second overload is also deliberately different to dict.update() |
|
|
# (if it were `Iterable[_T] | Iterable[tuple[_T, int]]`, |
|
|
# (if it were `IterableOrSupportsIntGetItem[_T] | IterableOrSupportsIntGetItem[tuple[_T, int]]`, |
|
|
# the tuples would be added as keys, breaking type safety) |
|
|
@overload # type: ignore[override] |
|
|
def update(self, __m: Mapping[_T, int], **kwargs: int) -> None: ... |
|
|
@overload |
|
|
def update(self, __m: Iterable[_T], **kwargs: int) -> None: ... |
|
|
def update(self, __m: IterableOrSupportsIntGetItem[_T], **kwargs: int) -> None: ... |
|
|
@overload |
|
|
def update(self, __m: None = ..., **kwargs: int) -> None: ... |
|
|
def __missing__(self, key: _T) -> int: ... |
|
Expand Down
Expand Up
|
@@ -352,10 +351,10 @@ class OrderedDict(dict[_KT, _VT], Reversible[_KT], Generic[_KT, _VT]): |
|
|
# See #3800 & https://github.com/python/typing/issues/548#issuecomment-683336963. |
|
|
@classmethod |
|
|
@overload |
|
|
def fromkeys(cls, iterable: Iterable[_T], value: None = ...) -> OrderedDict[_T, Any | None]: ... |
|
|
def fromkeys(cls, iterable: IterableOrSupportsIntGetItem[_T], value: None = ...) -> OrderedDict[_T, Any | None]: ... |
|
|
@classmethod |
|
|
@overload |
|
|
def fromkeys(cls, iterable: Iterable[_T], value: _S) -> OrderedDict[_T, _S]: ... |
|
|
def fromkeys(cls, iterable: IterableOrSupportsIntGetItem[_T], value: _S) -> OrderedDict[_T, _S]: ... |
|
|
# Keep OrderedDict.setdefault in line with MutableMapping.setdefault, modulo positional-only differences. |
|
|
@overload |
|
|
def setdefault(self: OrderedDict[_KT, _T | None], key: _KT) -> _T | None: ... |
|
Expand All
|
@@ -382,12 +381,12 @@ class defaultdict(dict[_KT, _VT], Generic[_KT, _VT]): |
|
|
**kwargs: _VT, |
|
|
) -> None: ... |
|
|
@overload |
|
|
def __init__(self, __default_factory: Callable[[], _VT] | None, __iterable: Iterable[tuple[_KT, _VT]]) -> None: ... |
|
|
def __init__(self, __default_factory: Callable[[], _VT] | None, __iterable: IterableOrSupportsIntGetItem[tuple[_KT, _VT]]) -> None: ... |
|
|
@overload |
|
|
def __init__( |
|
|
self: defaultdict[str, _VT], |
|
|
__default_factory: Callable[[], _VT] | None, |
|
|
__iterable: Iterable[tuple[str, _VT]], |
|
|
__iterable: IterableOrSupportsIntGetItem[tuple[str, _VT]], |
|
|
**kwargs: _VT, |
|
|
) -> None: ... |
|
|
def __missing__(self, __key: _KT) -> _VT: ... |
|
Expand Down
Expand Up
|
@@ -418,15 +417,15 @@ class ChainMap(MutableMapping[_KT, _VT], Generic[_KT, _VT]): |
|
|
# All arguments to `fromkeys` are passed to `dict.fromkeys` at runtime, so the signature should be kept in line with `dict.fromkeys`. |
|
|
@classmethod |
|
|
@overload |
|
|
def fromkeys(cls, iterable: Iterable[_T], __value: None = ...) -> ChainMap[_T, Any | None]: ... |
|
|
def fromkeys(cls, iterable: IterableOrSupportsIntGetItem[_T], __value: None = ...) -> ChainMap[_T, Any | None]: ... |
|
|
@classmethod |
|
|
@overload |
|
|
def fromkeys(cls, __iterable: Iterable[_T], __value: _S) -> ChainMap[_T, _S]: ... |
|
|
def fromkeys(cls, __iterable: IterableOrSupportsIntGetItem[_T], __value: _S) -> ChainMap[_T, _S]: ... |
|
|
if sys.version_info >= (3, 9): |
|
|
def __or__(self, other: Mapping[_T1, _T2]) -> ChainMap[_KT | _T1, _VT | _T2]: ... |
|
|
def __ror__(self, other: Mapping[_T1, _T2]) -> ChainMap[_KT | _T1, _VT | _T2]: ... |
|
|
# ChainMap.__ior__ should be kept roughly in line with MutableMapping.update() |
|
|
@overload # type: ignore[misc] |
|
|
def __ior__(self: Self, other: SupportsKeysAndGetItem[_KT, _VT]) -> Self: ... |
|
|
@overload |
|
|
def __ior__(self: Self, other: Iterable[tuple[_KT, _VT]]) -> Self: ... |
|
|
def __ior__(self: Self, other: IterableOrSupportsIntGetItem[tuple[_KT, _VT]]) -> Self: ... |