massive update, probably broken
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-pyright / node_modules / pyright / dist / typeshed-fallback / stdlib / typing.pyi
1 import collections  # Needed by aliases like DefaultDict, see mypy issue 2986
2 import sys
3 from abc import ABCMeta, abstractmethod
4 from types import BuiltinFunctionType, CodeType, FrameType, FunctionType, MethodType, ModuleType, TracebackType
5 from typing_extensions import Literal as _Literal, ParamSpec as _ParamSpec, final as _final
6
7 if sys.version_info >= (3, 7):
8     from types import MethodDescriptorType, MethodWrapperType, WrapperDescriptorType
9
10 if sys.version_info >= (3, 9):
11     from types import GenericAlias
12
13 # Definitions of special type checking related constructs.  Their definitions
14 # are not used, so their value does not matter.
15
16 Any = object()
17
18 class TypeVar:
19     __name__: str
20     __bound__: Type[Any] | None
21     __constraints__: Tuple[Type[Any], ...]
22     __covariant__: bool
23     __contravariant__: bool
24     def __init__(
25         self,
26         name: str,
27         *constraints: Type[Any],
28         bound: None | Type[Any] | str = ...,
29         covariant: bool = ...,
30         contravariant: bool = ...,
31     ) -> None: ...
32
33 _promote = object()
34
35 class _SpecialForm:
36     def __getitem__(self, typeargs: Any) -> object: ...
37
38 _F = TypeVar("_F", bound=Callable[..., Any])
39 _P = _ParamSpec("_P")
40 _T = TypeVar("_T")
41
42 def overload(func: _F) -> _F: ...
43
44 Union: _SpecialForm = ...
45 Optional: _SpecialForm = ...
46 Tuple: _SpecialForm = ...
47 Generic: _SpecialForm = ...
48 # Protocol is only present in 3.8 and later, but mypy needs it unconditionally
49 Protocol: _SpecialForm = ...
50 Callable: _SpecialForm = ...
51 Type: _SpecialForm = ...
52 ClassVar: _SpecialForm = ...
53 NoReturn: _SpecialForm = ...
54 if sys.version_info >= (3, 8):
55     Final: _SpecialForm = ...
56     def final(f: _T) -> _T: ...
57     Literal: _SpecialForm = ...
58     # TypedDict is a (non-subscriptable) special form.
59     TypedDict: object
60
61 if sys.version_info < (3, 7):
62     class GenericMeta(type): ...
63
64 if sys.version_info >= (3, 10):
65     class ParamSpecArgs:
66         __origin__: ParamSpec
67         def __init__(self, origin: ParamSpec) -> None: ...
68     class ParamSpecKwargs:
69         __origin__: ParamSpec
70         def __init__(self, origin: ParamSpec) -> None: ...
71     class ParamSpec:
72         __name__: str
73         __bound__: Type[Any] | None
74         __covariant__: bool
75         __contravariant__: bool
76         def __init__(
77             self, name: str, *, bound: None | Type[Any] | str = ..., contravariant: bool = ..., covariant: bool = ...
78         ) -> None: ...
79         @property
80         def args(self) -> ParamSpecArgs: ...
81         @property
82         def kwargs(self) -> ParamSpecKwargs: ...
83     Concatenate: _SpecialForm = ...
84     TypeAlias: _SpecialForm = ...
85     TypeGuard: _SpecialForm = ...
86
87 # These type variables are used by the container types.
88 _S = TypeVar("_S")
89 _KT = TypeVar("_KT")  # Key type.
90 _VT = TypeVar("_VT")  # Value type.
91 _T_co = TypeVar("_T_co", covariant=True)  # Any type covariant containers.
92 _V_co = TypeVar("_V_co", covariant=True)  # Any type covariant containers.
93 _KT_co = TypeVar("_KT_co", covariant=True)  # Key type covariant containers.
94 _VT_co = TypeVar("_VT_co", covariant=True)  # Value type covariant containers.
95 _T_contra = TypeVar("_T_contra", contravariant=True)  # Ditto contravariant.
96 _TC = TypeVar("_TC", bound=Type[object])
97
98 def no_type_check(arg: _F) -> _F: ...
99 def no_type_check_decorator(decorator: Callable[_P, _T]) -> Callable[_P, _T]: ...  # type: ignore
100
101 # Type aliases and type constructors
102
103 class _Alias:
104     # Class for defining generic aliases for library types.
105     def __getitem__(self, typeargs: Any) -> Any: ...
106
107 List = _Alias()
108 Dict = _Alias()
109 DefaultDict = _Alias()
110 Set = _Alias()
111 FrozenSet = _Alias()
112 Counter = _Alias()
113 Deque = _Alias()
114 ChainMap = _Alias()
115
116 if sys.version_info >= (3, 7):
117     OrderedDict = _Alias()
118
119 if sys.version_info >= (3, 9):
120     Annotated: _SpecialForm = ...
121
122 # Predefined type variables.
123 AnyStr = TypeVar("AnyStr", str, bytes)
124
125 # Abstract base classes.
126
127 def runtime_checkable(cls: _TC) -> _TC: ...
128 @runtime_checkable
129 class SupportsInt(Protocol, metaclass=ABCMeta):
130     @abstractmethod
131     def __int__(self) -> int: ...
132
133 @runtime_checkable
134 class SupportsFloat(Protocol, metaclass=ABCMeta):
135     @abstractmethod
136     def __float__(self) -> float: ...
137
138 @runtime_checkable
139 class SupportsComplex(Protocol, metaclass=ABCMeta):
140     @abstractmethod
141     def __complex__(self) -> complex: ...
142
143 @runtime_checkable
144 class SupportsBytes(Protocol, metaclass=ABCMeta):
145     @abstractmethod
146     def __bytes__(self) -> bytes: ...
147
148 if sys.version_info >= (3, 8):
149     @runtime_checkable
150     class SupportsIndex(Protocol, metaclass=ABCMeta):
151         @abstractmethod
152         def __index__(self) -> int: ...
153
154 @runtime_checkable
155 class SupportsAbs(Protocol[_T_co]):
156     @abstractmethod
157     def __abs__(self) -> _T_co: ...
158
159 @runtime_checkable
160 class SupportsRound(Protocol[_T_co]):
161     @overload
162     @abstractmethod
163     def __round__(self) -> int: ...
164     @overload
165     @abstractmethod
166     def __round__(self, __ndigits: int) -> _T_co: ...
167
168 @runtime_checkable
169 class Sized(Protocol, metaclass=ABCMeta):
170     @abstractmethod
171     def __len__(self) -> int: ...
172
173 @runtime_checkable
174 class Hashable(Protocol, metaclass=ABCMeta):
175     # TODO: This is special, in that a subclass of a hashable class may not be hashable
176     #   (for example, list vs. object). It's not obvious how to represent this. This class
177     #   is currently mostly useless for static checking.
178     @abstractmethod
179     def __hash__(self) -> int: ...
180
181 @runtime_checkable
182 class Iterable(Protocol[_T_co]):
183     @abstractmethod
184     def __iter__(self) -> Iterator[_T_co]: ...
185
186 @runtime_checkable
187 class Iterator(Iterable[_T_co], Protocol[_T_co]):
188     @abstractmethod
189     def __next__(self) -> _T_co: ...
190     def __iter__(self) -> Iterator[_T_co]: ...
191
192 @runtime_checkable
193 class Reversible(Iterable[_T_co], Protocol[_T_co]):
194     @abstractmethod
195     def __reversed__(self) -> Iterator[_T_co]: ...
196
197 class Generator(Iterator[_T_co], Generic[_T_co, _T_contra, _V_co]):
198     def __next__(self) -> _T_co: ...
199     @abstractmethod
200     def send(self, __value: _T_contra) -> _T_co: ...
201     @overload
202     @abstractmethod
203     def throw(
204         self, __typ: Type[BaseException], __val: BaseException | object = ..., __tb: TracebackType | None = ...
205     ) -> _T_co: ...
206     @overload
207     @abstractmethod
208     def throw(self, __typ: BaseException, __val: None = ..., __tb: TracebackType | None = ...) -> _T_co: ...
209     def close(self) -> None: ...
210     def __iter__(self) -> Generator[_T_co, _T_contra, _V_co]: ...
211     @property
212     def gi_code(self) -> CodeType: ...
213     @property
214     def gi_frame(self) -> FrameType: ...
215     @property
216     def gi_running(self) -> bool: ...
217     @property
218     def gi_yieldfrom(self) -> Generator[Any, Any, Any] | None: ...
219
220 @runtime_checkable
221 class Awaitable(Protocol[_T_co]):
222     @abstractmethod
223     def __await__(self) -> Generator[Any, None, _T_co]: ...
224
225 class Coroutine(Awaitable[_V_co], Generic[_T_co, _T_contra, _V_co]):
226     __name__: str
227     __qualname__: str
228     @property
229     def cr_await(self) -> Any | None: ...
230     @property
231     def cr_code(self) -> CodeType: ...
232     @property
233     def cr_frame(self) -> FrameType: ...
234     @property
235     def cr_running(self) -> bool: ...
236     @abstractmethod
237     def send(self, __value: _T_contra) -> _T_co: ...
238     @overload
239     @abstractmethod
240     def throw(
241         self, __typ: Type[BaseException], __val: BaseException | object = ..., __tb: TracebackType | None = ...
242     ) -> _T_co: ...
243     @overload
244     @abstractmethod
245     def throw(self, __typ: BaseException, __val: None = ..., __tb: TracebackType | None = ...) -> _T_co: ...
246     @abstractmethod
247     def close(self) -> None: ...
248
249 # NOTE: This type does not exist in typing.py or PEP 484.
250 # The parameters correspond to Generator, but the 4th is the original type.
251 class AwaitableGenerator(
252     Awaitable[_V_co], Generator[_T_co, _T_contra, _V_co], Generic[_T_co, _T_contra, _V_co, _S], metaclass=ABCMeta
253 ): ...
254
255 @runtime_checkable
256 class AsyncIterable(Protocol[_T_co]):
257     @abstractmethod
258     def __aiter__(self) -> AsyncIterator[_T_co]: ...
259
260 @runtime_checkable
261 class AsyncIterator(AsyncIterable[_T_co], Protocol[_T_co]):
262     @abstractmethod
263     def __anext__(self) -> Awaitable[_T_co]: ...
264     def __aiter__(self) -> AsyncIterator[_T_co]: ...
265
266 class AsyncGenerator(AsyncIterator[_T_co], Generic[_T_co, _T_contra]):
267     @abstractmethod
268     def __anext__(self) -> Awaitable[_T_co]: ...
269     @abstractmethod
270     def asend(self, __value: _T_contra) -> Awaitable[_T_co]: ...
271     @overload
272     @abstractmethod
273     def athrow(
274         self, __typ: Type[BaseException], __val: BaseException | object = ..., __tb: TracebackType | None = ...
275     ) -> Awaitable[_T_co]: ...
276     @overload
277     @abstractmethod
278     def athrow(self, __typ: BaseException, __val: None = ..., __tb: TracebackType | None = ...) -> Awaitable[_T_co]: ...
279     @abstractmethod
280     def aclose(self) -> Awaitable[None]: ...
281     @abstractmethod
282     def __aiter__(self) -> AsyncGenerator[_T_co, _T_contra]: ...
283     @property
284     def ag_await(self) -> Any: ...
285     @property
286     def ag_code(self) -> CodeType: ...
287     @property
288     def ag_frame(self) -> FrameType: ...
289     @property
290     def ag_running(self) -> bool: ...
291
292 @runtime_checkable
293 class Container(Protocol[_T_co]):
294     @abstractmethod
295     def __contains__(self, __x: object) -> bool: ...
296
297 @runtime_checkable
298 class Collection(Iterable[_T_co], Container[_T_co], Protocol[_T_co]):
299     # Implement Sized (but don't have it as a base class).
300     @abstractmethod
301     def __len__(self) -> int: ...
302
303 class Sequence(Collection[_T_co], Reversible[_T_co], Generic[_T_co]):
304     @overload
305     @abstractmethod
306     def __getitem__(self, i: int) -> _T_co: ...
307     @overload
308     @abstractmethod
309     def __getitem__(self, s: slice) -> Sequence[_T_co]: ...
310     # Mixin methods
311     def index(self, value: Any, start: int = ..., stop: int = ...) -> int: ...
312     def count(self, value: Any) -> int: ...
313     def __contains__(self, x: object) -> bool: ...
314     def __iter__(self) -> Iterator[_T_co]: ...
315     def __reversed__(self) -> Iterator[_T_co]: ...
316
317 class MutableSequence(Sequence[_T], Generic[_T]):
318     @abstractmethod
319     def insert(self, index: int, value: _T) -> None: ...
320     @overload
321     @abstractmethod
322     def __getitem__(self, i: int) -> _T: ...
323     @overload
324     @abstractmethod
325     def __getitem__(self, s: slice) -> MutableSequence[_T]: ...
326     @overload
327     @abstractmethod
328     def __setitem__(self, i: int, o: _T) -> None: ...
329     @overload
330     @abstractmethod
331     def __setitem__(self, s: slice, o: Iterable[_T]) -> None: ...
332     @overload
333     @abstractmethod
334     def __delitem__(self, i: int) -> None: ...
335     @overload
336     @abstractmethod
337     def __delitem__(self, i: slice) -> None: ...
338     # Mixin methods
339     def append(self, value: _T) -> None: ...
340     def clear(self) -> None: ...
341     def extend(self, values: Iterable[_T]) -> None: ...
342     def reverse(self) -> None: ...
343     def pop(self, index: int = ...) -> _T: ...
344     def remove(self, value: _T) -> None: ...
345     def __iadd__(self, x: Iterable[_T]) -> MutableSequence[_T]: ...
346
347 class AbstractSet(Collection[_T_co], Generic[_T_co]):
348     @abstractmethod
349     def __contains__(self, x: object) -> bool: ...
350     # Mixin methods
351     def __le__(self, s: AbstractSet[Any]) -> bool: ...
352     def __lt__(self, s: AbstractSet[Any]) -> bool: ...
353     def __gt__(self, s: AbstractSet[Any]) -> bool: ...
354     def __ge__(self, s: AbstractSet[Any]) -> bool: ...
355     def __and__(self, s: AbstractSet[Any]) -> AbstractSet[_T_co]: ...
356     def __or__(self, s: AbstractSet[_T]) -> AbstractSet[_T_co | _T]: ...
357     def __sub__(self, s: AbstractSet[Any]) -> AbstractSet[_T_co]: ...
358     def __xor__(self, s: AbstractSet[_T]) -> AbstractSet[_T_co | _T]: ...
359     def isdisjoint(self, other: Iterable[Any]) -> bool: ...
360
361 class MutableSet(AbstractSet[_T], Generic[_T]):
362     @abstractmethod
363     def add(self, value: _T) -> None: ...
364     @abstractmethod
365     def discard(self, value: _T) -> None: ...
366     # Mixin methods
367     def clear(self) -> None: ...
368     def pop(self) -> _T: ...
369     def remove(self, value: _T) -> None: ...
370     def __ior__(self, s: AbstractSet[_S]) -> MutableSet[_T | _S]: ...
371     def __iand__(self, s: AbstractSet[Any]) -> MutableSet[_T]: ...
372     def __ixor__(self, s: AbstractSet[_S]) -> MutableSet[_T | _S]: ...
373     def __isub__(self, s: AbstractSet[Any]) -> MutableSet[_T]: ...
374
375 class MappingView(Sized):
376     def __init__(self, mapping: Mapping[Any, Any]) -> None: ...  # undocumented
377     def __len__(self) -> int: ...
378
379 class ItemsView(MappingView, AbstractSet[Tuple[_KT_co, _VT_co]], Generic[_KT_co, _VT_co]):
380     def __init__(self, mapping: Mapping[_KT_co, _VT_co]) -> None: ...  # undocumented
381     def __and__(self, o: Iterable[Any]) -> set[tuple[_KT_co, _VT_co]]: ...
382     def __rand__(self, o: Iterable[_T]) -> set[_T]: ...
383     def __contains__(self, o: object) -> bool: ...
384     def __iter__(self) -> Iterator[tuple[_KT_co, _VT_co]]: ...
385     if sys.version_info >= (3, 8):
386         def __reversed__(self) -> Iterator[tuple[_KT_co, _VT_co]]: ...
387     def __or__(self, o: Iterable[_T]) -> set[tuple[_KT_co, _VT_co] | _T]: ...
388     def __ror__(self, o: Iterable[_T]) -> set[tuple[_KT_co, _VT_co] | _T]: ...
389     def __sub__(self, o: Iterable[Any]) -> set[tuple[_KT_co, _VT_co]]: ...
390     def __rsub__(self, o: Iterable[_T]) -> set[_T]: ...
391     def __xor__(self, o: Iterable[_T]) -> set[tuple[_KT_co, _VT_co] | _T]: ...
392     def __rxor__(self, o: Iterable[_T]) -> set[tuple[_KT_co, _VT_co] | _T]: ...
393
394 class KeysView(MappingView, AbstractSet[_KT_co], Generic[_KT_co]):
395     def __init__(self, mapping: Mapping[_KT_co, Any]) -> None: ...  # undocumented
396     def __and__(self, o: Iterable[Any]) -> set[_KT_co]: ...
397     def __rand__(self, o: Iterable[_T]) -> set[_T]: ...
398     def __contains__(self, o: object) -> bool: ...
399     def __iter__(self) -> Iterator[_KT_co]: ...
400     if sys.version_info >= (3, 8):
401         def __reversed__(self) -> Iterator[_KT_co]: ...
402     def __or__(self, o: Iterable[_T]) -> set[_KT_co | _T]: ...
403     def __ror__(self, o: Iterable[_T]) -> set[_KT_co | _T]: ...
404     def __sub__(self, o: Iterable[Any]) -> set[_KT_co]: ...
405     def __rsub__(self, o: Iterable[_T]) -> set[_T]: ...
406     def __xor__(self, o: Iterable[_T]) -> set[_KT_co | _T]: ...
407     def __rxor__(self, o: Iterable[_T]) -> set[_KT_co | _T]: ...
408
409 class ValuesView(MappingView, Iterable[_VT_co], Generic[_VT_co]):
410     def __init__(self, mapping: Mapping[Any, _VT_co]) -> None: ...  # undocumented
411     def __contains__(self, o: object) -> bool: ...
412     def __iter__(self) -> Iterator[_VT_co]: ...
413     if sys.version_info >= (3, 8):
414         def __reversed__(self) -> Iterator[_VT_co]: ...
415
416 @runtime_checkable
417 class ContextManager(Protocol[_T_co]):
418     def __enter__(self) -> _T_co: ...
419     def __exit__(
420         self, __exc_type: Type[BaseException] | None, __exc_value: BaseException | None, __traceback: TracebackType | None
421     ) -> bool | None: ...
422
423 @runtime_checkable
424 class AsyncContextManager(Protocol[_T_co]):
425     def __aenter__(self) -> Awaitable[_T_co]: ...
426     def __aexit__(
427         self, __exc_type: Type[BaseException] | None, __exc_value: BaseException | None, __traceback: TracebackType | None
428     ) -> Awaitable[bool | None]: ...
429
430 class Mapping(Collection[_KT], Generic[_KT, _VT_co]):
431     # TODO: We wish the key type could also be covariant, but that doesn't work,
432     # see discussion in https://github.com/python/typing/pull/273.
433     @abstractmethod
434     def __getitem__(self, __k: _KT) -> _VT_co: ...
435     # Mixin methods
436     @overload
437     def get(self, key: _KT) -> _VT_co | None: ...
438     @overload
439     def get(self, __key: _KT, __default: _VT_co | _T) -> _VT_co | _T: ...
440     def items(self) -> ItemsView[_KT, _VT_co]: ...
441     def keys(self) -> KeysView[_KT]: ...
442     def values(self) -> ValuesView[_VT_co]: ...
443     def __contains__(self, __o: object) -> bool: ...
444
445 class MutableMapping(Mapping[_KT, _VT], Generic[_KT, _VT]):
446     @abstractmethod
447     def __setitem__(self, __k: _KT, __v: _VT) -> None: ...
448     @abstractmethod
449     def __delitem__(self, __v: _KT) -> None: ...
450     def clear(self) -> None: ...
451     @overload
452     def pop(self, __key: _KT) -> _VT: ...
453     @overload
454     def pop(self, __key: _KT, __default: _VT | _T = ...) -> _VT | _T: ...
455     def popitem(self) -> tuple[_KT, _VT]: ...
456     def setdefault(self, __key: _KT, __default: _VT = ...) -> _VT: ...
457     # 'update' used to take a Union, but using overloading is better.
458     # The second overloaded type here is a bit too general, because
459     # Mapping[Tuple[_KT, _VT], W] is a subclass of Iterable[Tuple[_KT, _VT]],
460     # but will always have the behavior of the first overloaded type
461     # at runtime, leading to keys of a mix of types _KT and Tuple[_KT, _VT].
462     # We don't currently have any way of forcing all Mappings to use
463     # the first overload, but by using overloading rather than a Union,
464     # mypy will commit to using the first overload when the argument is
465     # known to be a Mapping with unknown type parameters, which is closer
466     # to the behavior we want. See mypy issue  #1430.
467     @overload
468     def update(self, __m: Mapping[_KT, _VT], **kwargs: _VT) -> None: ...
469     @overload
470     def update(self, __m: Iterable[tuple[_KT, _VT]], **kwargs: _VT) -> None: ...
471     @overload
472     def update(self, **kwargs: _VT) -> None: ...
473
474 Text = str
475
476 TYPE_CHECKING = True
477
478 class IO(Iterator[AnyStr], Generic[AnyStr]):
479     # TODO use abstract properties
480     @property
481     def mode(self) -> str: ...
482     @property
483     def name(self) -> str: ...
484     @abstractmethod
485     def close(self) -> None: ...
486     @property
487     def closed(self) -> bool: ...
488     @abstractmethod
489     def fileno(self) -> int: ...
490     @abstractmethod
491     def flush(self) -> None: ...
492     @abstractmethod
493     def isatty(self) -> bool: ...
494     @abstractmethod
495     def read(self, n: int = ...) -> AnyStr: ...
496     @abstractmethod
497     def readable(self) -> bool: ...
498     @abstractmethod
499     def readline(self, limit: int = ...) -> AnyStr: ...
500     @abstractmethod
501     def readlines(self, hint: int = ...) -> list[AnyStr]: ...
502     @abstractmethod
503     def seek(self, offset: int, whence: int = ...) -> int: ...
504     @abstractmethod
505     def seekable(self) -> bool: ...
506     @abstractmethod
507     def tell(self) -> int: ...
508     @abstractmethod
509     def truncate(self, size: int | None = ...) -> int: ...
510     @abstractmethod
511     def writable(self) -> bool: ...
512     @abstractmethod
513     def write(self, s: AnyStr) -> int: ...
514     @abstractmethod
515     def writelines(self, lines: Iterable[AnyStr]) -> None: ...
516     @abstractmethod
517     def __next__(self) -> AnyStr: ...
518     @abstractmethod
519     def __iter__(self) -> Iterator[AnyStr]: ...
520     @abstractmethod
521     def __enter__(self) -> IO[AnyStr]: ...
522     @abstractmethod
523     def __exit__(
524         self, t: Type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None
525     ) -> bool | None: ...
526
527 class BinaryIO(IO[bytes]):
528     @abstractmethod
529     def __enter__(self) -> BinaryIO: ...
530
531 class TextIO(IO[str]):
532     # TODO use abstractproperty
533     @property
534     def buffer(self) -> BinaryIO: ...
535     @property
536     def encoding(self) -> str: ...
537     @property
538     def errors(self) -> str | None: ...
539     @property
540     def line_buffering(self) -> int: ...  # int on PyPy, bool on CPython
541     @property
542     def newlines(self) -> Any: ...  # None, str or tuple
543     @abstractmethod
544     def __enter__(self) -> TextIO: ...
545
546 class ByteString(Sequence[int], metaclass=ABCMeta): ...
547
548 @_final
549 class Match(Generic[AnyStr]):
550     pos: int
551     endpos: int
552     lastindex: int | None
553     lastgroup: AnyStr | None
554     string: AnyStr
555
556     # The regular expression object whose match() or search() method produced
557     # this match instance.
558     re: Pattern[AnyStr]
559     def expand(self, template: AnyStr) -> AnyStr: ...
560     # group() returns "AnyStr" or "AnyStr | None", depending on the pattern.
561     @overload
562     def group(self, __group: _Literal[0] = ...) -> AnyStr: ...
563     @overload
564     def group(self, __group: str | int) -> AnyStr | Any: ...
565     @overload
566     def group(self, __group1: str | int, __group2: str | int, *groups: str | int) -> Tuple[AnyStr | Any, ...]: ...
567     # Each item of groups()'s return tuple is either "AnyStr" or
568     # "AnyStr | None", depending on the pattern.
569     @overload
570     def groups(self) -> Tuple[AnyStr | Any, ...]: ...
571     @overload
572     def groups(self, default: _T) -> Tuple[AnyStr | _T, ...]: ...
573     # Each value in groupdict()'s return dict is either "AnyStr" or
574     # "AnyStr | None", depending on the pattern.
575     @overload
576     def groupdict(self) -> dict[str, AnyStr | Any]: ...
577     @overload
578     def groupdict(self, default: _T) -> dict[str, AnyStr | _T]: ...
579     def start(self, __group: int | str = ...) -> int: ...
580     def end(self, __group: int | str = ...) -> int: ...
581     def span(self, __group: int | str = ...) -> tuple[int, int]: ...
582     @property
583     def regs(self) -> Tuple[tuple[int, int], ...]: ...  # undocumented
584     # __getitem__() returns "AnyStr" or "AnyStr | None", depending on the pattern.
585     @overload
586     def __getitem__(self, __key: _Literal[0]) -> AnyStr: ...
587     @overload
588     def __getitem__(self, __key: int | str) -> AnyStr | Any: ...
589     if sys.version_info >= (3, 9):
590         def __class_getitem__(cls, item: Any) -> GenericAlias: ...
591
592 @_final
593 class Pattern(Generic[AnyStr]):
594     flags: int
595     groupindex: Mapping[str, int]
596     groups: int
597     pattern: AnyStr
598     def search(self, string: AnyStr, pos: int = ..., endpos: int = ...) -> Match[AnyStr] | None: ...
599     def match(self, string: AnyStr, pos: int = ..., endpos: int = ...) -> Match[AnyStr] | None: ...
600     def fullmatch(self, string: AnyStr, pos: int = ..., endpos: int = ...) -> Match[AnyStr] | None: ...
601     def split(self, string: AnyStr, maxsplit: int = ...) -> list[AnyStr]: ...
602     def findall(self, string: AnyStr, pos: int = ..., endpos: int = ...) -> list[Any]: ...
603     def finditer(self, string: AnyStr, pos: int = ..., endpos: int = ...) -> Iterator[Match[AnyStr]]: ...
604     @overload
605     def sub(self, repl: AnyStr, string: AnyStr, count: int = ...) -> AnyStr: ...
606     @overload
607     def sub(self, repl: Callable[[Match[AnyStr]], AnyStr], string: AnyStr, count: int = ...) -> AnyStr: ...
608     @overload
609     def subn(self, repl: AnyStr, string: AnyStr, count: int = ...) -> tuple[AnyStr, int]: ...
610     @overload
611     def subn(self, repl: Callable[[Match[AnyStr]], AnyStr], string: AnyStr, count: int = ...) -> tuple[AnyStr, int]: ...
612     if sys.version_info >= (3, 9):
613         def __class_getitem__(cls, item: Any) -> GenericAlias: ...
614
615 # Functions
616
617 if sys.version_info >= (3, 7):
618     _get_type_hints_obj_allowed_types = Union[
619         object,
620         Callable[..., Any],
621         FunctionType,
622         BuiltinFunctionType,
623         MethodType,
624         ModuleType,
625         WrapperDescriptorType,
626         MethodWrapperType,
627         MethodDescriptorType,
628     ]
629 else:
630     _get_type_hints_obj_allowed_types = Union[
631         object, Callable[..., Any], FunctionType, BuiltinFunctionType, MethodType, ModuleType,
632     ]
633
634 if sys.version_info >= (3, 9):
635     def get_type_hints(
636         obj: _get_type_hints_obj_allowed_types,
637         globalns: dict[str, Any] | None = ...,
638         localns: dict[str, Any] | None = ...,
639         include_extras: bool = ...,
640     ) -> dict[str, Any]: ...
641
642 else:
643     def get_type_hints(
644         obj: _get_type_hints_obj_allowed_types, globalns: dict[str, Any] | None = ..., localns: dict[str, Any] | None = ...
645     ) -> dict[str, Any]: ...
646
647 if sys.version_info >= (3, 8):
648     def get_origin(tp: Any) -> Any | None: ...
649     def get_args(tp: Any) -> Tuple[Any, ...]: ...
650
651 @overload
652 def cast(typ: Type[_T], val: Any) -> _T: ...
653 @overload
654 def cast(typ: str, val: Any) -> Any: ...
655 @overload
656 def cast(typ: object, val: Any) -> Any: ...
657
658 # Type constructors
659
660 # NamedTuple is special-cased in the type checker
661 class NamedTuple(Tuple[Any, ...]):
662     _field_types: collections.OrderedDict[str, Type[Any]]
663     _field_defaults: dict[str, Any]
664     _fields: Tuple[str, ...]
665     _source: str
666     @overload
667     def __init__(self, typename: str, fields: Iterable[tuple[str, Any]] = ...) -> None: ...
668     @overload
669     def __init__(self, typename: str, fields: None = ..., **kwargs: Any) -> None: ...
670     @classmethod
671     def _make(cls: Type[_T], iterable: Iterable[Any]) -> _T: ...
672     if sys.version_info >= (3, 8):
673         def _asdict(self) -> dict[str, Any]: ...
674     else:
675         def _asdict(self) -> collections.OrderedDict[str, Any]: ...
676     def _replace(self: _T, **kwargs: Any) -> _T: ...
677
678 # Internal mypy fallback type for all typed dicts (does not exist at runtime)
679 class _TypedDict(Mapping[str, object], metaclass=ABCMeta):
680     def copy(self: _T) -> _T: ...
681     # Using NoReturn so that only calls using mypy plugin hook that specialize the signature
682     # can go through.
683     def setdefault(self, k: NoReturn, default: object) -> object: ...
684     # Mypy plugin hook for 'pop' expects that 'default' has a type variable type.
685     def pop(self, k: NoReturn, default: _T = ...) -> object: ...  # type: ignore
686     def update(self: _T, __m: _T) -> None: ...
687     def __delitem__(self, k: NoReturn) -> None: ...
688     def items(self) -> ItemsView[str, object]: ...
689     def keys(self) -> KeysView[str]: ...
690     def values(self) -> ValuesView[object]: ...
691     def __or__(self: _T, __value: _T) -> _T: ...
692     def __ior__(self: _T, __value: _T) -> _T: ...
693
694 def NewType(name: str, tp: Type[_T]) -> Type[_T]: ...
695
696 # This itself is only available during type checking
697 def type_check_only(func_or_cls: _F) -> _F: ...
698
699 if sys.version_info >= (3, 7):
700     class ForwardRef:
701         __forward_arg__: str
702         __forward_code__: CodeType
703         __forward_evaluated__: bool
704         __forward_value__: Any | None
705         __forward_is_argument__: bool
706         if sys.version_info >= (3, 9):
707             # The module argument was added in Python 3.9.7.
708             def __init__(self, arg: str, is_argument: bool = ..., module: Any | None = ...) -> None: ...
709         else:
710             def __init__(self, arg: str, is_argument: bool = ...) -> None: ...
711         def _evaluate(self, globalns: dict[str, Any] | None, localns: dict[str, Any] | None) -> Any | None: ...
712         def __eq__(self, other: Any) -> bool: ...
713         def __hash__(self) -> int: ...
714         def __repr__(self) -> str: ...
715
716 if sys.version_info >= (3, 10):
717     def is_typeddict(tp: Any) -> bool: ...