Skip to content

Commit 1cc62a2

Browse files
Sync typeshed (#16493)
Source commit: python/typeshed@643d911
1 parent 5489fd3 commit 1cc62a2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+208
-171
lines changed

mypy/typeshed/stdlib/_ast.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ if sys.version_info >= (3, 10):
553553

554554
class MatchSingleton(pattern):
555555
__match_args__ = ("value",)
556-
value: Literal[True, False, None]
556+
value: Literal[True, False] | None
557557

558558
class MatchSequence(pattern):
559559
__match_args__ = ("patterns",)

mypy/typeshed/stdlib/_locale.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import sys
22
from _typeshed import StrPath
3-
from collections.abc import Iterable, Mapping
3+
from collections.abc import Mapping
44

55
LC_CTYPE: int
66
LC_COLLATE: int
@@ -10,7 +10,7 @@ LC_NUMERIC: int
1010
LC_ALL: int
1111
CHAR_MAX: int
1212

13-
def setlocale(category: int, locale: str | Iterable[str | None] | None = None) -> str: ...
13+
def setlocale(__category: int, __locale: str | None = None) -> str: ...
1414
def localeconv() -> Mapping[str, int | str | list[int]]: ...
1515

1616
if sys.version_info >= (3, 11):

mypy/typeshed/stdlib/_typeshed/__init__.pyi

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,10 @@ class SupportsNoArgReadline(Protocol[_T_co]):
236236
class SupportsWrite(Protocol[_T_contra]):
237237
def write(self, __s: _T_contra) -> object: ...
238238

239+
# stable
240+
class SupportsFlush(Protocol):
241+
def flush(self) -> object: ...
242+
239243
# Unfortunately PEP 688 does not allow us to distinguish read-only
240244
# from writable buffers. We use these aliases for readability for now.
241245
# Perhaps a future extension of the buffer protocol will allow us to

mypy/typeshed/stdlib/_typeshed/wsgi.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ from typing import Any, Protocol
1111
from typing_extensions import TypeAlias
1212

1313
class _Readable(Protocol):
14-
def read(self, size: int = ...) -> bytes: ...
14+
def read(self, __size: int = ...) -> bytes: ...
1515
# Optional: def close(self) -> object: ...
1616

1717
if sys.version_info >= (3, 11):

mypy/typeshed/stdlib/_typeshed/xml.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ from typing import Any, Protocol
44

55
# As defined https://docs.python.org/3/library/xml.dom.html#domimplementation-objects
66
class DOMImplementation(Protocol):
7-
def hasFeature(self, feature: str, version: str | None) -> bool: ...
8-
def createDocument(self, namespaceUri: str, qualifiedName: str, doctype: Any | None) -> Any: ...
9-
def createDocumentType(self, qualifiedName: str, publicId: str, systemId: str) -> Any: ...
7+
def hasFeature(self, __feature: str, __version: str | None) -> bool: ...
8+
def createDocument(self, __namespaceUri: str, __qualifiedName: str, __doctype: Any | None) -> Any: ...
9+
def createDocumentType(self, __qualifiedName: str, __publicId: str, __systemId: str) -> Any: ...

mypy/typeshed/stdlib/_warnings.pyi

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,36 @@
1+
import sys
12
from typing import Any, overload
23

34
_defaultaction: str
45
_onceregistry: dict[Any, Any]
56
filters: list[tuple[str, str | None, type[Warning], str | None, int]]
67

7-
@overload
8-
def warn(message: str, category: type[Warning] | None = None, stacklevel: int = 1, source: Any | None = None) -> None: ...
9-
@overload
10-
def warn(message: Warning, category: Any = None, stacklevel: int = 1, source: Any | None = None) -> None: ...
8+
if sys.version_info >= (3, 12):
9+
@overload
10+
def warn(
11+
message: str,
12+
category: type[Warning] | None = None,
13+
stacklevel: int = 1,
14+
source: Any | None = None,
15+
*,
16+
skip_file_prefixes: tuple[str, ...] = (),
17+
) -> None: ...
18+
@overload
19+
def warn(
20+
message: Warning,
21+
category: Any = None,
22+
stacklevel: int = 1,
23+
source: Any | None = None,
24+
*,
25+
skip_file_prefixes: tuple[str, ...] = (),
26+
) -> None: ...
27+
28+
else:
29+
@overload
30+
def warn(message: str, category: type[Warning] | None = None, stacklevel: int = 1, source: Any | None = None) -> None: ...
31+
@overload
32+
def warn(message: Warning, category: Any = None, stacklevel: int = 1, source: Any | None = None) -> None: ...
33+
1134
@overload
1235
def warn_explicit(
1336
message: str,

mypy/typeshed/stdlib/argparse.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ class _ActionsContainer:
120120
def _handle_conflict_resolve(self, action: Action, conflicting_actions: Iterable[tuple[str, Action]]) -> None: ...
121121

122122
class _FormatterClass(Protocol):
123-
def __call__(self, prog: str) -> HelpFormatter: ...
123+
def __call__(self, *, prog: str) -> HelpFormatter: ...
124124

125125
class ArgumentParser(_AttributeHolder, _ActionsContainer):
126126
prog: str

mypy/typeshed/stdlib/ast.pyi

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,30 @@ from _ast import *
44
from _typeshed import ReadableBuffer, Unused
55
from collections.abc import Iterator
66
from typing import Any, TypeVar as _TypeVar, overload
7-
from typing_extensions import Literal
7+
from typing_extensions import Literal, deprecated
88

99
if sys.version_info >= (3, 8):
1010
class _ABC(type):
1111
if sys.version_info >= (3, 9):
1212
def __init__(cls, *args: Unused) -> None: ...
1313

14+
@deprecated("Replaced by ast.Constant; removal scheduled for Python 3.14")
1415
class Num(Constant, metaclass=_ABC):
1516
value: int | float | complex
16-
17+
@deprecated("Replaced by ast.Constant; removal scheduled for Python 3.14")
1718
class Str(Constant, metaclass=_ABC):
1819
value: str
1920
# Aliases for value, for backwards compatibility
2021
s: str
21-
22+
@deprecated("Replaced by ast.Constant; removal scheduled for Python 3.14")
2223
class Bytes(Constant, metaclass=_ABC):
2324
value: bytes
2425
# Aliases for value, for backwards compatibility
2526
s: bytes
26-
27+
@deprecated("Replaced by ast.Constant; removal scheduled for Python 3.14")
2728
class NameConstant(Constant, metaclass=_ABC): ...
29+
30+
@deprecated("Replaced by ast.Constant; removal scheduled for Python 3.14")
2831
class Ellipsis(Constant, metaclass=_ABC): ...
2932

3033
if sys.version_info >= (3, 9):

mypy/typeshed/stdlib/asyncio/base_events.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ class BaseEventLoop(AbstractEventLoop):
423423
bufsize: Literal[0] = 0,
424424
encoding: None = None,
425425
errors: None = None,
426-
text: Literal[False, None] = None,
426+
text: Literal[False] | None = None,
427427
**kwargs: Any,
428428
) -> tuple[SubprocessTransport, _ProtocolT]: ...
429429
async def subprocess_exec(

mypy/typeshed/stdlib/asyncio/events.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ class AbstractEventLoop:
522522
bufsize: Literal[0] = 0,
523523
encoding: None = None,
524524
errors: None = None,
525-
text: Literal[False, None] = ...,
525+
text: Literal[False] | None = ...,
526526
**kwargs: Any,
527527
) -> tuple[SubprocessTransport, _ProtocolT]: ...
528528
@abstractmethod

mypy/typeshed/stdlib/asyncio/proactor_events.pyi

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
11
import sys
22
from collections.abc import Mapping
33
from socket import socket
4-
from typing import Any, ClassVar, Protocol
4+
from typing import Any, ClassVar
55
from typing_extensions import Literal
66

77
from . import base_events, constants, events, futures, streams, transports
88

99
__all__ = ("BaseProactorEventLoop",)
1010

11-
if sys.version_info >= (3, 8):
12-
class _WarnCallbackProtocol(Protocol):
13-
def __call__(
14-
self, message: str, category: type[Warning] | None = ..., stacklevel: int = ..., source: Any | None = ...
15-
) -> object: ...
16-
1711
class _ProactorBasePipeTransport(transports._FlowControlMixin, transports.BaseTransport):
1812
def __init__(
1913
self,
@@ -24,10 +18,7 @@ class _ProactorBasePipeTransport(transports._FlowControlMixin, transports.BaseTr
2418
extra: Mapping[Any, Any] | None = None,
2519
server: events.AbstractServer | None = None,
2620
) -> None: ...
27-
if sys.version_info >= (3, 8):
28-
def __del__(self, _warn: _WarnCallbackProtocol = ...) -> None: ...
29-
else:
30-
def __del__(self) -> None: ...
21+
def __del__(self) -> None: ...
3122

3223
class _ProactorReadPipeTransport(_ProactorBasePipeTransport, transports.ReadTransport):
3324
if sys.version_info >= (3, 10):

mypy/typeshed/stdlib/asyncio/subprocess.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ if sys.version_info >= (3, 11):
5454
bufsize: Literal[0] = 0,
5555
encoding: None = None,
5656
errors: None = None,
57-
text: Literal[False, None] = None,
57+
text: Literal[False] | None = None,
5858
# These parameters are taken by subprocess.Popen, which this ultimately delegates to
5959
executable: StrOrBytesPath | None = None,
6060
preexec_fn: Callable[[], Any] | None = None,
@@ -120,7 +120,7 @@ elif sys.version_info >= (3, 10):
120120
bufsize: Literal[0] = 0,
121121
encoding: None = None,
122122
errors: None = None,
123-
text: Literal[False, None] = None,
123+
text: Literal[False] | None = None,
124124
# These parameters are taken by subprocess.Popen, which this ultimately delegates to
125125
executable: StrOrBytesPath | None = None,
126126
preexec_fn: Callable[[], Any] | None = None,
@@ -185,7 +185,7 @@ else: # >= 3.9
185185
bufsize: Literal[0] = 0,
186186
encoding: None = None,
187187
errors: None = None,
188-
text: Literal[False, None] = None,
188+
text: Literal[False] | None = None,
189189
# These parameters are taken by subprocess.Popen, which this ultimately delegates to
190190
executable: StrOrBytesPath | None = None,
191191
preexec_fn: Callable[[], Any] | None = None,

mypy/typeshed/stdlib/asyncio/unix_events.pyi

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,6 @@ if sys.platform != "win32":
8484
DefaultEventLoopPolicy = _UnixDefaultEventLoopPolicy
8585

8686
if sys.version_info >= (3, 8):
87-
from typing import Protocol
88-
89-
class _Warn(Protocol):
90-
def __call__(
91-
self, message: str, category: type[Warning] | None = ..., stacklevel: int = ..., source: Any | None = ...
92-
) -> object: ...
93-
9487
class MultiLoopChildWatcher(AbstractChildWatcher):
9588
def is_active(self) -> bool: ...
9689
def close(self) -> None: ...
@@ -109,7 +102,7 @@ if sys.platform != "win32":
109102
def __exit__(
110103
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: types.TracebackType | None
111104
) -> None: ...
112-
def __del__(self, _warn: _Warn = ...) -> None: ...
105+
def __del__(self) -> None: ...
113106
def add_child_handler(self, pid: int, callback: Callable[..., object], *args: Any) -> None: ...
114107
def remove_child_handler(self, pid: int) -> bool: ...
115108
def attach_loop(self, loop: AbstractEventLoop | None) -> None: ...

mypy/typeshed/stdlib/asyncio/windows_utils.pyi

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,20 @@ import subprocess
22
import sys
33
from collections.abc import Callable
44
from types import TracebackType
5-
from typing import Any, AnyStr, Protocol
5+
from typing import Any, AnyStr
66
from typing_extensions import Literal, Self
77

88
if sys.platform == "win32":
99
__all__ = ("pipe", "Popen", "PIPE", "PipeHandle")
1010

11-
class _WarnFunction(Protocol):
12-
def __call__(
13-
self, message: str, category: type[Warning] = ..., stacklevel: int = ..., source: PipeHandle = ...
14-
) -> object: ...
1511
BUFSIZE: Literal[8192]
1612
PIPE = subprocess.PIPE
1713
STDOUT = subprocess.STDOUT
1814
def pipe(*, duplex: bool = False, overlapped: tuple[bool, bool] = (True, True), bufsize: int = 8192) -> tuple[int, int]: ...
1915

2016
class PipeHandle:
2117
def __init__(self, handle: int) -> None: ...
22-
if sys.version_info >= (3, 8):
23-
def __del__(self, _warn: _WarnFunction = ...) -> None: ...
24-
else:
25-
def __del__(self) -> None: ...
26-
18+
def __del__(self) -> None: ...
2719
def __enter__(self) -> Self: ...
2820
def __exit__(self, t: type[BaseException] | None, v: BaseException | None, tb: TracebackType | None) -> None: ...
2921
@property

mypy/typeshed/stdlib/builtins.pyi

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ from _typeshed import (
1818
SupportsAiter,
1919
SupportsAnext,
2020
SupportsDivMod,
21+
SupportsFlush,
2122
SupportsIter,
2223
SupportsKeysAndGetItem,
2324
SupportsLenAndGetItem,
@@ -1194,7 +1195,7 @@ if sys.version_info >= (3, 10):
11941195
# See discussion in #7491 and pure-Python implementation of `anext` at https://github.com/python/cpython/blob/ea786a882b9ed4261eafabad6011bc7ef3b5bf94/Lib/test/test_asyncgen.py#L52-L80
11951196
def anext(__i: _SupportsSynchronousAnext[_AwaitableT]) -> _AwaitableT: ...
11961197
@overload
1197-
async def anext(__i: SupportsAnext[_T], default: _VT) -> _T | _VT: ...
1198+
async def anext(__i: SupportsAnext[_T], __default: _VT) -> _T | _VT: ...
11981199

11991200
# compile() returns a CodeType, unless the flags argument includes PyCF_ONLY_AST (=1024),
12001201
# in which case it returns ast.AST. We have overloads for flag 0 (the default) and for
@@ -1340,9 +1341,9 @@ def getattr(__o: object, __name: str, __default: None) -> Any | None: ...
13401341
@overload
13411342
def getattr(__o: object, __name: str, __default: bool) -> Any | bool: ...
13421343
@overload
1343-
def getattr(__o: object, name: str, __default: list[Any]) -> Any | list[Any]: ...
1344+
def getattr(__o: object, __name: str, __default: list[Any]) -> Any | list[Any]: ...
13441345
@overload
1345-
def getattr(__o: object, name: str, __default: dict[Any, Any]) -> Any | dict[Any, Any]: ...
1346+
def getattr(__o: object, __name: str, __default: dict[Any, Any]) -> Any | dict[Any, Any]: ...
13461347
@overload
13471348
def getattr(__o: object, __name: str, __default: _T) -> Any | _T: ...
13481349
def globals() -> dict[str, Any]: ...
@@ -1357,13 +1358,13 @@ class _GetItemIterable(Protocol[_T_co]):
13571358
def __getitem__(self, __i: int) -> _T_co: ...
13581359

13591360
@overload
1360-
def iter(__iterable: SupportsIter[_SupportsNextT]) -> _SupportsNextT: ...
1361+
def iter(__object: SupportsIter[_SupportsNextT]) -> _SupportsNextT: ...
13611362
@overload
1362-
def iter(__iterable: _GetItemIterable[_T]) -> Iterator[_T]: ...
1363+
def iter(__object: _GetItemIterable[_T]) -> Iterator[_T]: ...
13631364
@overload
1364-
def iter(__function: Callable[[], _T | None], __sentinel: None) -> Iterator[_T]: ...
1365+
def iter(__object: Callable[[], _T | None], __sentinel: None) -> Iterator[_T]: ...
13651366
@overload
1366-
def iter(__function: Callable[[], _T], __sentinel: object) -> Iterator[_T]: ...
1367+
def iter(__object: Callable[[], _T], __sentinel: object) -> Iterator[_T]: ...
13671368

13681369
# Keep this alias in sync with unittest.case._ClassInfo
13691370
if sys.version_info >= (3, 10):
@@ -1544,8 +1545,7 @@ def open(
15441545
) -> IO[Any]: ...
15451546
def ord(__c: str | bytes | bytearray) -> int: ...
15461547

1547-
class _SupportsWriteAndFlush(SupportsWrite[_T_contra], Protocol[_T_contra]):
1548-
def flush(self) -> None: ...
1548+
class _SupportsWriteAndFlush(SupportsWrite[_T_contra], SupportsFlush, Protocol[_T_contra]): ...
15491549

15501550
@overload
15511551
def print(

mypy/typeshed/stdlib/cmath.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def exp(__z: _C) -> complex: ...
3030
def isclose(a: _C, b: _C, *, rel_tol: SupportsFloat = 1e-09, abs_tol: SupportsFloat = 0.0) -> bool: ...
3131
def isinf(__z: _C) -> bool: ...
3232
def isnan(__z: _C) -> bool: ...
33-
def log(__x: _C, __y_obj: _C = ...) -> complex: ...
33+
def log(__x: _C, __base: _C = ...) -> complex: ...
3434
def log10(__z: _C) -> complex: ...
3535
def phase(__z: _C) -> float: ...
3636
def polar(__z: _C) -> tuple[float, float]: ...

mypy/typeshed/stdlib/codecs.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ class StreamWriter(Codec):
213213
def reset(self) -> None: ...
214214
def __enter__(self) -> Self: ...
215215
def __exit__(self, type: type[BaseException] | None, value: BaseException | None, tb: types.TracebackType | None) -> None: ...
216-
def __getattr__(self, name: str, getattr: Callable[[str], Any] = ...) -> Any: ...
216+
def __getattr__(self, name: str, getattr: Callable[[Any, str], Any] = ...) -> Any: ...
217217

218218
class StreamReader(Codec):
219219
stream: _ReadableStream
@@ -227,7 +227,7 @@ class StreamReader(Codec):
227227
def __exit__(self, type: type[BaseException] | None, value: BaseException | None, tb: types.TracebackType | None) -> None: ...
228228
def __iter__(self) -> Self: ...
229229
def __next__(self) -> str: ...
230-
def __getattr__(self, name: str, getattr: Callable[[str], Any] = ...) -> Any: ...
230+
def __getattr__(self, name: str, getattr: Callable[[Any, str], Any] = ...) -> Any: ...
231231

232232
# Doesn't actually inherit from TextIO, but wraps a BinaryIO to provide text reading and writing
233233
# and delegates attributes to the underlying binary stream with __getattr__.

mypy/typeshed/stdlib/collections/__init__.pyi

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,13 @@ class OrderedDict(dict[_KT, _VT], Reversible[_KT], Generic[_KT, _VT]):
372372
def setdefault(self: OrderedDict[_KT, _T | None], key: _KT, default: None = None) -> _T | None: ...
373373
@overload
374374
def setdefault(self, key: _KT, default: _VT) -> _VT: ...
375+
# Same as dict.pop, but accepts keyword arguments
376+
@overload
377+
def pop(self, key: _KT) -> _VT: ...
378+
@overload
379+
def pop(self, key: _KT, default: _VT) -> _VT: ...
380+
@overload
381+
def pop(self, key: _KT, default: _T) -> _VT | _T: ...
375382
def __eq__(self, __value: object) -> bool: ...
376383
if sys.version_info >= (3, 9):
377384
@overload

mypy/typeshed/stdlib/compileall.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ from typing import Any, Protocol
66
__all__ = ["compile_dir", "compile_file", "compile_path"]
77

88
class _SupportsSearch(Protocol):
9-
def search(self, string: str) -> Any: ...
9+
def search(self, __string: str) -> Any: ...
1010

1111
if sys.version_info >= (3, 10):
1212
def compile_dir(

mypy/typeshed/stdlib/contextlib.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class AbstractAsyncContextManager(Protocol[_T_co]):
5656
class ContextDecorator:
5757
def __call__(self, func: _F) -> _F: ...
5858

59-
class _GeneratorContextManager(AbstractContextManager[_T_co], ContextDecorator, Generic[_T_co]):
59+
class _GeneratorContextManager(AbstractContextManager[_T_co], ContextDecorator):
6060
# __init__ and all instance attributes are actually inherited from _GeneratorContextManagerBase
6161
# _GeneratorContextManagerBase is more trouble than it's worth to include in the stub; see #6676
6262
def __init__(self, func: Callable[..., Iterator[_T_co]], args: tuple[Any, ...], kwds: dict[str, Any]) -> None: ...
@@ -81,7 +81,7 @@ if sys.version_info >= (3, 10):
8181
class AsyncContextDecorator:
8282
def __call__(self, func: _AF) -> _AF: ...
8383

84-
class _AsyncGeneratorContextManager(AbstractAsyncContextManager[_T_co], AsyncContextDecorator, Generic[_T_co]):
84+
class _AsyncGeneratorContextManager(AbstractAsyncContextManager[_T_co], AsyncContextDecorator):
8585
# __init__ and these attributes are actually defined in the base class _GeneratorContextManagerBase,
8686
# which is more trouble than it's worth to include in the stub (see #6676)
8787
def __init__(self, func: Callable[..., AsyncIterator[_T_co]], args: tuple[Any, ...], kwds: dict[str, Any]) -> None: ...

0 commit comments

Comments
 (0)