2 from _collections_abc import dict_items, dict_keys, dict_values
3 from _typeshed import Self
4 from typing import Any, Dict, Generic, NoReturn, Tuple, Type, TypeVar, overload
5 from typing_extensions import final
7 if sys.version_info >= (3, 10):
8 from typing import Callable, Iterable, Iterator, Mapping, MutableMapping, MutableSequence, Reversible, Sequence
10 from _collections_abc import *
16 _KT_co = TypeVar("_KT_co", covariant=True)
17 _VT_co = TypeVar("_VT_co", covariant=True)
19 # namedtuple is special-cased in the type checker; the initializer is ignored.
20 if sys.version_info >= (3, 7):
23 field_names: str | Iterable[str],
26 module: str | None = ...,
27 defaults: Iterable[Any] | None = ...,
28 ) -> Type[Tuple[Any, ...]]: ...
32 typename: str, field_names: str | Iterable[str], *, verbose: bool = ..., rename: bool = ..., module: str | None = ...
33 ) -> Type[Tuple[Any, ...]]: ...
35 class UserDict(MutableMapping[_KT, _VT]):
37 def __init__(self, __dict: Mapping[_KT, _VT] | None = ..., **kwargs: _VT) -> None: ...
38 def __len__(self) -> int: ...
39 def __getitem__(self, key: _KT) -> _VT: ...
40 def __setitem__(self, key: _KT, item: _VT) -> None: ...
41 def __delitem__(self, key: _KT) -> None: ...
42 def __iter__(self) -> Iterator[_KT]: ...
43 def __contains__(self, key: object) -> bool: ...
44 def copy(self: Self) -> Self: ...
46 def fromkeys(cls: Type[Self], iterable: Iterable[_KT], value: _VT | None = ...) -> Self: ...
48 class UserList(MutableSequence[_T]):
50 def __init__(self, initlist: Iterable[_T] | None = ...) -> None: ...
51 def __lt__(self, other: object) -> bool: ...
52 def __le__(self, other: object) -> bool: ...
53 def __gt__(self, other: object) -> bool: ...
54 def __ge__(self, other: object) -> bool: ...
55 def __contains__(self, item: object) -> bool: ...
56 def __len__(self) -> int: ...
58 def __getitem__(self, i: int) -> _T: ...
60 def __getitem__(self: Self, i: slice) -> Self: ...
62 def __setitem__(self, i: int, o: _T) -> None: ...
64 def __setitem__(self, i: slice, o: Iterable[_T]) -> None: ...
65 def __delitem__(self, i: int | slice) -> None: ...
66 def __add__(self: _S, other: Iterable[_T]) -> _S: ...
67 def __iadd__(self: _S, other: Iterable[_T]) -> _S: ...
68 def __mul__(self: _S, n: int) -> _S: ...
69 def __imul__(self: _S, n: int) -> _S: ...
70 def append(self, item: _T) -> None: ...
71 def insert(self, i: int, item: _T) -> None: ...
72 def pop(self, i: int = ...) -> _T: ...
73 def remove(self, item: _T) -> None: ...
74 def clear(self) -> None: ...
75 def copy(self: _S) -> _S: ...
76 def count(self, item: _T) -> int: ...
77 def index(self, item: _T, *args: Any) -> int: ...
78 def reverse(self) -> None: ...
79 def sort(self, *args: Any, **kwds: Any) -> None: ...
80 def extend(self, other: Iterable[_T]) -> None: ...
82 _UserStringT = TypeVar("_UserStringT", bound=UserString)
84 class UserString(Sequence[str]):
86 def __init__(self, seq: object) -> None: ...
87 def __int__(self) -> int: ...
88 def __float__(self) -> float: ...
89 def __complex__(self) -> complex: ...
90 def __getnewargs__(self) -> tuple[str]: ...
91 def __lt__(self, string: str | UserString) -> bool: ...
92 def __le__(self, string: str | UserString) -> bool: ...
93 def __gt__(self, string: str | UserString) -> bool: ...
94 def __ge__(self, string: str | UserString) -> bool: ...
95 def __contains__(self, char: object) -> bool: ...
96 def __len__(self) -> int: ...
97 # It should return a str to implement Sequence correctly, but it doesn't.
98 def __getitem__(self: _UserStringT, i: int | slice) -> _UserStringT: ... # type: ignore
99 def __iter__(self: _UserStringT) -> Iterator[_UserStringT]: ... # type: ignore
100 def __reversed__(self: _UserStringT) -> Iterator[_UserStringT]: ... # type: ignore
101 def __add__(self: _UserStringT, other: object) -> _UserStringT: ...
102 def __mul__(self: _UserStringT, n: int) -> _UserStringT: ...
103 def __mod__(self: _UserStringT, args: Any) -> _UserStringT: ...
104 def capitalize(self: _UserStringT) -> _UserStringT: ...
105 def casefold(self: _UserStringT) -> _UserStringT: ...
106 def center(self: _UserStringT, width: int, *args: Any) -> _UserStringT: ...
107 def count(self, sub: str | UserString, start: int = ..., end: int = ...) -> int: ...
108 if sys.version_info >= (3, 8):
109 def encode(self: UserString, encoding: str | None = ..., errors: str | None = ...) -> bytes: ...
111 def encode(self: _UserStringT, encoding: str | None = ..., errors: str | None = ...) -> _UserStringT: ...
112 def endswith(self, suffix: str | Tuple[str, ...], start: int | None = ..., end: int | None = ...) -> bool: ...
113 def expandtabs(self: _UserStringT, tabsize: int = ...) -> _UserStringT: ...
114 def find(self, sub: str | UserString, start: int = ..., end: int = ...) -> int: ...
115 def format(self, *args: Any, **kwds: Any) -> str: ...
116 def format_map(self, mapping: Mapping[str, Any]) -> str: ...
117 def index(self, sub: str, start: int = ..., end: int = ...) -> int: ...
118 def isalpha(self) -> bool: ...
119 def isalnum(self) -> bool: ...
120 def isdecimal(self) -> bool: ...
121 def isdigit(self) -> bool: ...
122 def isidentifier(self) -> bool: ...
123 def islower(self) -> bool: ...
124 def isnumeric(self) -> bool: ...
125 def isprintable(self) -> bool: ...
126 def isspace(self) -> bool: ...
127 def istitle(self) -> bool: ...
128 def isupper(self) -> bool: ...
129 def join(self, seq: Iterable[str]) -> str: ...
130 def ljust(self: _UserStringT, width: int, *args: Any) -> _UserStringT: ...
131 def lower(self: _UserStringT) -> _UserStringT: ...
132 def lstrip(self: _UserStringT, chars: str | None = ...) -> _UserStringT: ...
135 def maketrans(x: dict[int, _T] | dict[str, _T] | dict[str | int, _T]) -> dict[int, _T]: ...
138 def maketrans(x: str, y: str, z: str = ...) -> dict[int, int | None]: ...
139 def partition(self, sep: str) -> tuple[str, str, str]: ...
140 if sys.version_info >= (3, 9):
141 def removeprefix(self: _UserStringT, __prefix: str | UserString) -> _UserStringT: ...
142 def removesuffix(self: _UserStringT, __suffix: str | UserString) -> _UserStringT: ...
143 def replace(self: _UserStringT, old: str | UserString, new: str | UserString, maxsplit: int = ...) -> _UserStringT: ...
144 def rfind(self, sub: str | UserString, start: int = ..., end: int = ...) -> int: ...
145 def rindex(self, sub: str | UserString, start: int = ..., end: int = ...) -> int: ...
146 def rjust(self: _UserStringT, width: int, *args: Any) -> _UserStringT: ...
147 def rpartition(self, sep: str) -> tuple[str, str, str]: ...
148 def rstrip(self: _UserStringT, chars: str | None = ...) -> _UserStringT: ...
149 def split(self, sep: str | None = ..., maxsplit: int = ...) -> list[str]: ...
150 def rsplit(self, sep: str | None = ..., maxsplit: int = ...) -> list[str]: ...
151 def splitlines(self, keepends: bool = ...) -> list[str]: ...
152 def startswith(self, prefix: str | Tuple[str, ...], start: int | None = ..., end: int | None = ...) -> bool: ...
153 def strip(self: _UserStringT, chars: str | None = ...) -> _UserStringT: ...
154 def swapcase(self: _UserStringT) -> _UserStringT: ...
155 def title(self: _UserStringT) -> _UserStringT: ...
156 def translate(self: _UserStringT, *args: Any) -> _UserStringT: ...
157 def upper(self: _UserStringT) -> _UserStringT: ...
158 def zfill(self: _UserStringT, width: int) -> _UserStringT: ...
160 class deque(MutableSequence[_T], Generic[_T]):
162 def maxlen(self) -> int | None: ...
163 def __init__(self, iterable: Iterable[_T] = ..., maxlen: int | None = ...) -> None: ...
164 def append(self, __x: _T) -> None: ...
165 def appendleft(self, __x: _T) -> None: ...
166 def clear(self) -> None: ...
167 def copy(self: _S) -> _S: ...
168 def count(self, __x: _T) -> int: ...
169 def extend(self, __iterable: Iterable[_T]) -> None: ...
170 def extendleft(self, __iterable: Iterable[_T]) -> None: ...
171 def insert(self, __i: int, __x: _T) -> None: ...
172 def index(self, __x: _T, __start: int = ..., __stop: int = ...) -> int: ...
173 def pop(self) -> _T: ... # type: ignore
174 def popleft(self) -> _T: ...
175 def remove(self, __value: _T) -> None: ...
176 def reverse(self) -> None: ...
177 def rotate(self, __n: int = ...) -> None: ...
178 def __copy__(self: _S) -> _S: ...
179 def __len__(self) -> int: ...
180 def __iter__(self) -> Iterator[_T]: ...
181 def __str__(self) -> str: ...
182 # These methods of deque don't really take slices, but we need to
183 # define them as taking a slice to satisfy MutableSequence.
185 def __getitem__(self, __index: int) -> _T: ...
187 def __getitem__(self, __s: slice) -> MutableSequence[_T]: ...
189 def __setitem__(self, __i: int, __x: _T) -> None: ...
191 def __setitem__(self, __s: slice, __o: Iterable[_T]) -> None: ...
193 def __delitem__(self, __i: int) -> None: ...
195 def __delitem__(self, __s: slice) -> None: ...
196 def __contains__(self, __o: object) -> bool: ...
197 def __reduce__(self: Self) -> tuple[Type[Self], tuple[()], None, Iterator[_T]]: ...
198 def __reversed__(self) -> Iterator[_T]: ...
199 def __iadd__(self: _S, __iterable: Iterable[_T]) -> _S: ...
200 def __add__(self: _S, __other: _S) -> _S: ...
201 def __mul__(self: _S, __other: int) -> _S: ...
202 def __imul__(self: _S, __other: int) -> _S: ...
204 class Counter(Dict[_T, int], Generic[_T]):
206 def __init__(self, __iterable: None = ..., **kwargs: int) -> None: ...
208 def __init__(self, __mapping: Mapping[_T, int]) -> None: ...
210 def __init__(self, __iterable: Iterable[_T]) -> None: ...
211 def copy(self: Self) -> Self: ...
212 def elements(self) -> Iterator[_T]: ...
213 def most_common(self, n: int | None = ...) -> list[tuple[_T, int]]: ...
215 def fromkeys(cls, iterable: Any, v: int | None = ...) -> NoReturn: ... # type: ignore
217 def subtract(self, __iterable: None = ...) -> None: ...
219 def subtract(self, __mapping: Mapping[_T, int]) -> None: ...
221 def subtract(self, __iterable: Iterable[_T]) -> None: ...
222 # The Iterable[Tuple[...]] argument type is not actually desirable
223 # (the tuples will be added as keys, breaking type safety) but
224 # it's included so that the signature is compatible with
225 # Dict.update. Not sure if we should use '# type: ignore' instead
226 # and omit the type from the union.
228 def update(self, __m: Mapping[_T, int], **kwargs: int) -> None: ...
230 def update(self, __m: Iterable[_T] | Iterable[tuple[_T, int]], **kwargs: int) -> None: ...
232 def update(self, __m: None = ..., **kwargs: int) -> None: ...
233 def __add__(self, other: Counter[_T]) -> Counter[_T]: ...
234 def __sub__(self, other: Counter[_T]) -> Counter[_T]: ...
235 def __and__(self, other: Counter[_T]) -> Counter[_T]: ...
236 def __or__(self, other: Counter[_T]) -> Counter[_T]: ... # type: ignore
237 def __pos__(self) -> Counter[_T]: ...
238 def __neg__(self) -> Counter[_T]: ...
239 def __iadd__(self, other: Counter[_T]) -> Counter[_T]: ...
240 def __isub__(self, other: Counter[_T]) -> Counter[_T]: ...
241 def __iand__(self, other: Counter[_T]) -> Counter[_T]: ...
242 def __ior__(self, other: Counter[_T]) -> Counter[_T]: ... # type: ignore
245 class _OrderedDictKeysView(dict_keys[_KT_co, _VT_co], Reversible[_KT_co]): # type: ignore[misc]
246 def __reversed__(self) -> Iterator[_KT_co]: ...
249 class _OrderedDictItemsView(dict_items[_KT_co, _VT_co], Reversible[Tuple[_KT_co, _VT_co]]): # type: ignore[misc]
250 def __reversed__(self) -> Iterator[tuple[_KT_co, _VT_co]]: ...
253 class _OrderedDictValuesView(dict_values[_KT_co, _VT_co], Reversible[_VT_co], Generic[_KT_co, _VT_co]): # type: ignore[misc]
254 def __reversed__(self) -> Iterator[_VT_co]: ...
256 class OrderedDict(Dict[_KT, _VT], Reversible[_KT], Generic[_KT, _VT]):
257 def popitem(self, last: bool = ...) -> tuple[_KT, _VT]: ...
258 def move_to_end(self, key: _KT, last: bool = ...) -> None: ...
259 def copy(self: Self) -> Self: ...
260 def __reversed__(self) -> Iterator[_KT]: ...
261 def keys(self) -> _OrderedDictKeysView[_KT, _VT]: ...
262 def items(self) -> _OrderedDictItemsView[_KT, _VT]: ...
263 def values(self) -> _OrderedDictValuesView[_KT, _VT]: ...
265 class defaultdict(Dict[_KT, _VT], Generic[_KT, _VT]):
266 default_factory: Callable[[], _VT] | None
268 def __init__(self, **kwargs: _VT) -> None: ...
270 def __init__(self, __default_factory: Callable[[], _VT] | None) -> None: ...
272 def __init__(self, __default_factory: Callable[[], _VT] | None, **kwargs: _VT) -> None: ...
274 def __init__(self, __default_factory: Callable[[], _VT] | None, __map: Mapping[_KT, _VT]) -> None: ...
276 def __init__(self, __default_factory: Callable[[], _VT] | None, __map: Mapping[_KT, _VT], **kwargs: _VT) -> None: ...
278 def __init__(self, __default_factory: Callable[[], _VT] | None, __iterable: Iterable[tuple[_KT, _VT]]) -> None: ...
281 self, __default_factory: Callable[[], _VT] | None, __iterable: Iterable[tuple[_KT, _VT]], **kwargs: _VT
283 def __missing__(self, __key: _KT) -> _VT: ...
284 def __copy__(self: _S) -> _S: ...
285 def copy(self: _S) -> _S: ...
287 class ChainMap(MutableMapping[_KT, _VT], Generic[_KT, _VT]):
288 maps: list[MutableMapping[_KT, _VT]]
289 def __init__(self, *maps: MutableMapping[_KT, _VT]) -> None: ...
290 def new_child(self: Self, m: MutableMapping[_KT, _VT] | None = ...) -> Self: ...
292 def parents(self: Self) -> Self: ...
293 def __setitem__(self, k: _KT, v: _VT) -> None: ...
294 def __delitem__(self, v: _KT) -> None: ...
295 def __getitem__(self, k: _KT) -> _VT: ...
296 def __iter__(self) -> Iterator[_KT]: ...
297 def __len__(self) -> int: ...
298 def __missing__(self, key: _KT) -> _VT: ... # undocumented
299 def setdefault(self, key: _KT, default: _VT = ...) -> _VT: ...
301 def pop(self, key: _KT) -> _VT: ...
303 def pop(self, key: _KT, default: _VT | _T = ...) -> _VT | _T: ...