Skip to content

Commit b49be10

Browse files
Sync typeshed (#15873)
Source commit: python/typeshed@74aac1a
1 parent 854a9f8 commit b49be10

File tree

14 files changed

+175
-32
lines changed

14 files changed

+175
-32
lines changed

mypy/typeshed/stdlib/asyncio/base_events.pyi

+45-2
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,48 @@ class BaseEventLoop(AbstractEventLoop):
107107
flags: int = 0,
108108
) -> list[tuple[AddressFamily, SocketKind, int, str, tuple[str, int] | tuple[str, int, int, int]]]: ...
109109
async def getnameinfo(self, sockaddr: tuple[str, int] | tuple[str, int, int, int], flags: int = 0) -> tuple[str, str]: ...
110-
if sys.version_info >= (3, 11):
110+
if sys.version_info >= (3, 12):
111+
@overload
112+
async def create_connection(
113+
self,
114+
protocol_factory: Callable[[], _ProtocolT],
115+
host: str = ...,
116+
port: int = ...,
117+
*,
118+
ssl: _SSLContext = None,
119+
family: int = 0,
120+
proto: int = 0,
121+
flags: int = 0,
122+
sock: None = None,
123+
local_addr: tuple[str, int] | None = None,
124+
server_hostname: str | None = None,
125+
ssl_handshake_timeout: float | None = None,
126+
ssl_shutdown_timeout: float | None = None,
127+
happy_eyeballs_delay: float | None = None,
128+
interleave: int | None = None,
129+
all_errors: bool = False,
130+
) -> tuple[Transport, _ProtocolT]: ...
131+
@overload
132+
async def create_connection(
133+
self,
134+
protocol_factory: Callable[[], _ProtocolT],
135+
host: None = None,
136+
port: None = None,
137+
*,
138+
ssl: _SSLContext = None,
139+
family: int = 0,
140+
proto: int = 0,
141+
flags: int = 0,
142+
sock: socket,
143+
local_addr: None = None,
144+
server_hostname: str | None = None,
145+
ssl_handshake_timeout: float | None = None,
146+
ssl_shutdown_timeout: float | None = None,
147+
happy_eyeballs_delay: float | None = None,
148+
interleave: int | None = None,
149+
all_errors: bool = False,
150+
) -> tuple[Transport, _ProtocolT]: ...
151+
elif sys.version_info >= (3, 11):
111152
@overload
112153
async def create_connection(
113154
self,
@@ -426,5 +467,7 @@ class BaseEventLoop(AbstractEventLoop):
426467
# Debug flag management.
427468
def get_debug(self) -> bool: ...
428469
def set_debug(self, enabled: bool) -> None: ...
429-
if sys.version_info >= (3, 9):
470+
if sys.version_info >= (3, 12):
471+
async def shutdown_default_executor(self, timeout: float | None = None) -> None: ...
472+
elif sys.version_info >= (3, 9):
430473
async def shutdown_default_executor(self) -> None: ...

mypy/typeshed/stdlib/asyncio/constants.pyi

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ if sys.version_info >= (3, 11):
1111
SSL_SHUTDOWN_TIMEOUT: float
1212
FLOW_CONTROL_HIGH_WATER_SSL_READ: Literal[256]
1313
FLOW_CONTROL_HIGH_WATER_SSL_WRITE: Literal[512]
14+
if sys.version_info >= (3, 12):
15+
THREAD_JOIN_TIMEOUT: Literal[300]
1416

1517
class _SendfileMode(enum.Enum):
1618
UNSUPPORTED: int

mypy/typeshed/stdlib/asyncio/events.pyi

+2
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ class Handle:
7676
def cancel(self) -> None: ...
7777
def _run(self) -> None: ...
7878
def cancelled(self) -> bool: ...
79+
if sys.version_info >= (3, 12):
80+
def get_context(self) -> Context: ...
7981

8082
class TimerHandle(Handle):
8183
def __init__(

mypy/typeshed/stdlib/asyncio/streams.pyi

+10-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,16 @@ class StreamWriter:
148148
async def wait_closed(self) -> None: ...
149149
def get_extra_info(self, name: str, default: Any = None) -> Any: ...
150150
async def drain(self) -> None: ...
151-
if sys.version_info >= (3, 11):
151+
if sys.version_info >= (3, 12):
152+
async def start_tls(
153+
self,
154+
sslcontext: ssl.SSLContext,
155+
*,
156+
server_hostname: str | None = None,
157+
ssl_handshake_timeout: float | None = None,
158+
ssl_shutdown_timeout: float | None = None,
159+
) -> None: ...
160+
elif sys.version_info >= (3, 11):
152161
async def start_tls(
153162
self, sslcontext: ssl.SSLContext, *, server_hostname: str | None = None, ssl_handshake_timeout: float | None = None
154163
) -> None: ...

mypy/typeshed/stdlib/asyncio/tasks.pyi

+22-1
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,26 @@ else:
285285
# since the only reason why `asyncio.Future` is invariant is the `set_result()` method,
286286
# and `asyncio.Task.set_result()` always raises.
287287
class Task(Future[_T_co], Generic[_T_co]): # type: ignore[type-var] # pyright: ignore[reportGeneralTypeIssues]
288-
if sys.version_info >= (3, 8):
288+
if sys.version_info >= (3, 12):
289+
def __init__(
290+
self,
291+
coro: _TaskCompatibleCoro[_T_co],
292+
*,
293+
loop: AbstractEventLoop = ...,
294+
name: str | None,
295+
context: Context | None = None,
296+
eager_start: bool = False,
297+
) -> None: ...
298+
elif sys.version_info >= (3, 11):
299+
def __init__(
300+
self,
301+
coro: _TaskCompatibleCoro[_T_co],
302+
*,
303+
loop: AbstractEventLoop = ...,
304+
name: str | None,
305+
context: Context | None = None,
306+
) -> None: ...
307+
elif sys.version_info >= (3, 8):
289308
def __init__(
290309
self, coro: _TaskCompatibleCoro[_T_co], *, loop: AbstractEventLoop = ..., name: str | None = ...
291310
) -> None: ...
@@ -295,6 +314,8 @@ class Task(Future[_T_co], Generic[_T_co]): # type: ignore[type-var] # pyright:
295314
def get_coro(self) -> _TaskCompatibleCoro[_T_co]: ...
296315
def get_name(self) -> str: ...
297316
def set_name(self, __value: object) -> None: ...
317+
if sys.version_info >= (3, 12):
318+
def get_context(self) -> Context: ...
298319

299320
def get_stack(self, *, limit: int | None = None) -> list[FrameType]: ...
300321
def print_stack(self, *, limit: int | None = None, file: TextIO | None = None) -> None: ...

mypy/typeshed/stdlib/enum.pyi

+4-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import _typeshed
22
import sys
33
import types
44
from _typeshed import SupportsKeysAndGetItem, Unused
5-
from abc import ABCMeta
65
from builtins import property as _builtins_property
76
from collections.abc import Callable, Iterable, Iterator, Mapping
87
from typing import Any, Generic, TypeVar, overload
@@ -76,12 +75,8 @@ class _EnumDict(dict[str, Any]):
7675
@overload
7776
def update(self, members: Iterable[tuple[str, Any]], **more_members: Any) -> None: ...
7877

79-
# Note: EnumMeta actually subclasses type directly, not ABCMeta.
80-
# This is a temporary workaround to allow multiple creation of enums with builtins
81-
# such as str as mixins, which due to the handling of ABCs of builtin types, cause
82-
# spurious inconsistent metaclass structure. See #1595.
8378
# Structurally: Iterable[T], Reversible[T], Container[T] where T is the enum itself
84-
class EnumMeta(ABCMeta):
79+
class EnumMeta(type):
8580
if sys.version_info >= (3, 11):
8681
def __new__(
8782
metacls: type[_typeshed.Self],
@@ -193,6 +188,9 @@ class Enum(metaclass=EnumMeta):
193188
def __hash__(self) -> int: ...
194189
def __format__(self, format_spec: str) -> str: ...
195190
def __reduce_ex__(self, proto: Unused) -> tuple[Any, ...]: ...
191+
if sys.version_info >= (3, 12):
192+
def __copy__(self) -> Self: ...
193+
def __deepcopy__(self, memo: Any) -> Self: ...
196194

197195
if sys.version_info >= (3, 11):
198196
class ReprEnum(Enum): ...

mypy/typeshed/stdlib/importlib/metadata/__init__.pyi

+1
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ class MetadataPathFinder(DistributionFinder):
180180
def invalidate_caches(cls) -> None: ...
181181

182182
class PathDistribution(Distribution):
183+
_path: Path
183184
def __init__(self, path: Path) -> None: ...
184185
def read_text(self, filename: StrPath) -> str: ...
185186
def locate_file(self, path: StrPath) -> PathLike[str]: ...

mypy/typeshed/stdlib/logging/__init__.pyi

+16-2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ __all__ = [
6060

6161
if sys.version_info >= (3, 11):
6262
__all__ += ["getLevelNamesMapping"]
63+
if sys.version_info >= (3, 12):
64+
__all__ += ["getHandlerByName", "getHandlerNames"]
6365

6466
_SysExcInfoType: TypeAlias = tuple[type[BaseException], BaseException, TracebackType | None] | tuple[None, None, None]
6567
_ExcInfoType: TypeAlias = None | bool | _SysExcInfoType | BaseException
@@ -83,7 +85,10 @@ class Filterer:
8385
filters: list[_FilterType]
8486
def addFilter(self, filter: _FilterType) -> None: ...
8587
def removeFilter(self, filter: _FilterType) -> None: ...
86-
def filter(self, record: LogRecord) -> bool: ...
88+
if sys.version_info >= (3, 12):
89+
def filter(self, record: LogRecord) -> bool | LogRecord: ...
90+
else:
91+
def filter(self, record: LogRecord) -> bool: ...
8792

8893
class Manager: # undocumented
8994
root: RootLogger
@@ -111,6 +116,8 @@ class Logger(Filterer):
111116
def isEnabledFor(self, level: int) -> bool: ...
112117
def getEffectiveLevel(self) -> int: ...
113118
def getChild(self, suffix: str) -> Self: ... # see python/typing#980
119+
if sys.version_info >= (3, 12):
120+
def getChildren(self) -> set[Logger]: ...
114121
if sys.version_info >= (3, 8):
115122
def debug(
116123
self,
@@ -324,6 +331,10 @@ class Handler(Filterer):
324331
def format(self, record: LogRecord) -> str: ...
325332
def emit(self, record: LogRecord) -> None: ...
326333

334+
if sys.version_info >= (3, 12):
335+
def getHandlerByName(name: str) -> Handler | None: ...
336+
def getHandlerNames() -> frozenset[str]: ...
337+
327338
class Formatter:
328339
converter: Callable[[float | None], struct_time]
329340
_fmt: str | None # undocumented
@@ -370,7 +381,10 @@ class Filter:
370381
name: str # undocumented
371382
nlen: int # undocumented
372383
def __init__(self, name: str = "") -> None: ...
373-
def filter(self, record: LogRecord) -> bool: ...
384+
if sys.version_info >= (3, 12):
385+
def filter(self, record: LogRecord) -> bool | LogRecord: ...
386+
else:
387+
def filter(self, record: LogRecord) -> bool: ...
374388

375389
class LogRecord:
376390
# args can be set to None by logging.handlers.QueueHandler

mypy/typeshed/stdlib/socket.pyi

+1
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ if sys.platform != "win32" and sys.platform != "darwin":
201201
TCP_LINGER2 as TCP_LINGER2,
202202
TCP_QUICKACK as TCP_QUICKACK,
203203
TCP_SYNCNT as TCP_SYNCNT,
204+
TCP_USER_TIMEOUT as TCP_USER_TIMEOUT,
204205
TCP_WINDOW_CLAMP as TCP_WINDOW_CLAMP,
205206
)
206207
if sys.platform != "win32":

mypy/typeshed/stdlib/sre_parse.pyi

+19-5
Original file line numberDiff line numberDiff line change
@@ -87,25 +87,39 @@ class Tokenizer:
8787
def seek(self, index: int) -> None: ...
8888
def error(self, msg: str, offset: int = 0) -> _Error: ...
8989

90-
if sys.version_info >= (3, 11):
90+
if sys.version_info >= (3, 12):
91+
def checkgroupname(self, name: str, offset: int) -> None: ...
92+
elif sys.version_info >= (3, 11):
9193
def checkgroupname(self, name: str, offset: int, nested: int) -> None: ...
9294

9395
def fix_flags(src: str | bytes, flags: int) -> int: ...
9496

9597
_TemplateType: TypeAlias = tuple[list[tuple[int, int]], list[str | None]]
9698
_TemplateByteType: TypeAlias = tuple[list[tuple[int, int]], list[bytes | None]]
97-
if sys.version_info >= (3, 8):
98-
def parse(str: str, flags: int = 0, state: State | None = None) -> SubPattern: ...
99+
100+
if sys.version_info >= (3, 12):
101+
@overload
102+
def parse_template(source: str, pattern: _Pattern[Any]) -> _TemplateType: ...
103+
@overload
104+
def parse_template(source: bytes, pattern: _Pattern[Any]) -> _TemplateByteType: ...
105+
106+
elif sys.version_info >= (3, 8):
99107
@overload
100108
def parse_template(source: str, state: _Pattern[Any]) -> _TemplateType: ...
101109
@overload
102110
def parse_template(source: bytes, state: _Pattern[Any]) -> _TemplateByteType: ...
103111

104112
else:
105-
def parse(str: str, flags: int = 0, pattern: Pattern | None = None) -> SubPattern: ...
106113
@overload
107114
def parse_template(source: str, pattern: _Pattern[Any]) -> _TemplateType: ...
108115
@overload
109116
def parse_template(source: bytes, pattern: _Pattern[Any]) -> _TemplateByteType: ...
110117

111-
def expand_template(template: _TemplateType, match: Match[Any]) -> str: ...
118+
if sys.version_info >= (3, 8):
119+
def parse(str: str, flags: int = 0, state: State | None = None) -> SubPattern: ...
120+
121+
else:
122+
def parse(str: str, flags: int = 0, pattern: Pattern | None = None) -> SubPattern: ...
123+
124+
if sys.version_info < (3, 12):
125+
def expand_template(template: _TemplateType, match: Match[Any]) -> str: ...

mypy/typeshed/stdlib/ssl.pyi

+28-13
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,20 @@ class SSLCertVerificationError(SSLError, ValueError):
4444

4545
CertificateError = SSLCertVerificationError
4646

47-
def wrap_socket(
48-
sock: socket.socket,
49-
keyfile: StrOrBytesPath | None = None,
50-
certfile: StrOrBytesPath | None = None,
51-
server_side: bool = False,
52-
cert_reqs: int = ...,
53-
ssl_version: int = ...,
54-
ca_certs: str | None = None,
55-
do_handshake_on_connect: bool = True,
56-
suppress_ragged_eofs: bool = True,
57-
ciphers: str | None = None,
58-
) -> SSLSocket: ...
47+
if sys.version_info < (3, 12):
48+
def wrap_socket(
49+
sock: socket.socket,
50+
keyfile: StrOrBytesPath | None = None,
51+
certfile: StrOrBytesPath | None = None,
52+
server_side: bool = False,
53+
cert_reqs: int = ...,
54+
ssl_version: int = ...,
55+
ca_certs: str | None = None,
56+
do_handshake_on_connect: bool = True,
57+
suppress_ragged_eofs: bool = True,
58+
ciphers: str | None = None,
59+
) -> SSLSocket: ...
60+
5961
def create_default_context(
6062
purpose: Purpose = ...,
6163
*,
@@ -95,7 +97,10 @@ else:
9597
_create_default_https_context: Callable[..., SSLContext]
9698

9799
def RAND_bytes(__n: int) -> bytes: ...
98-
def RAND_pseudo_bytes(__n: int) -> tuple[bytes, bool]: ...
100+
101+
if sys.version_info < (3, 12):
102+
def RAND_pseudo_bytes(__n: int) -> tuple[bytes, bool]: ...
103+
99104
def RAND_status() -> bool: ...
100105
def RAND_egd(path: str) -> None: ...
101106
def RAND_add(__string: str | ReadableBuffer, __entropy: float) -> None: ...
@@ -198,6 +203,11 @@ class Options(enum.IntFlag):
198203
OP_ENABLE_MIDDLEBOX_COMPAT: int
199204
if sys.platform == "linux":
200205
OP_IGNORE_UNEXPECTED_EOF: int
206+
if sys.version_info >= (3, 12):
207+
OP_LEGACY_SERVER_CONNECT: int
208+
if sys.version_info >= (3, 12) and sys.platform != "linux":
209+
OP_ENABLE_KTLS: int
210+
OP_IGNORE_UNEXPECTED_EOF: int
201211

202212
OP_ALL: Options
203213
OP_NO_SSLv2: Options
@@ -216,6 +226,11 @@ if sys.version_info >= (3, 8):
216226
OP_ENABLE_MIDDLEBOX_COMPAT: Options
217227
if sys.platform == "linux":
218228
OP_IGNORE_UNEXPECTED_EOF: Options
229+
if sys.version_info >= (3, 12):
230+
OP_LEGACY_SERVER_CONNECT: Options
231+
if sys.version_info >= (3, 12) and sys.platform != "linux":
232+
OP_ENABLE_KTLS: Options
233+
OP_IGNORE_UNEXPECTED_EOF: Options
219234

220235
HAS_NEVER_CHECK_COMMON_NAME: bool
221236
HAS_SSLv2: bool

mypy/typeshed/stdlib/turtle.pyi

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import sys
12
from collections.abc import Callable, Sequence
23
from tkinter import Canvas, Frame, Misc, PhotoImage, Scrollbar
34
from typing import Any, ClassVar, overload
@@ -249,6 +250,9 @@ class TNavigator:
249250
def reset(self) -> None: ...
250251
def degrees(self, fullcircle: float = 360.0) -> None: ...
251252
def radians(self) -> None: ...
253+
if sys.version_info >= (3, 12):
254+
def teleport(self, x: float | None = None, y: float | None = None, *, fill_gap: bool = False) -> None: ...
255+
252256
def forward(self, distance: float) -> None: ...
253257
def back(self, distance: float) -> None: ...
254258
def right(self, angle: float) -> None: ...
@@ -321,6 +325,9 @@ class TPen:
321325
def color(self, r: float, g: float, b: float) -> None: ...
322326
@overload
323327
def color(self, color1: _Color, color2: _Color) -> None: ...
328+
if sys.version_info >= (3, 12):
329+
def teleport(self, x: float | None = None, y: float | None = None, *, fill_gap: bool = False) -> None: ...
330+
324331
def showturtle(self) -> None: ...
325332
def hideturtle(self) -> None: ...
326333
def isvisible(self) -> bool: ...

mypy/typeshed/stdlib/typing.pyi

+9-1
Original file line numberDiff line numberDiff line change
@@ -900,8 +900,16 @@ class _TypedDict(Mapping[str, object], metaclass=ABCMeta):
900900
def keys(self) -> dict_keys[str, object]: ...
901901
def values(self) -> dict_values[str, object]: ...
902902
if sys.version_info >= (3, 9):
903+
@overload
903904
def __or__(self, __value: typing_extensions.Self) -> typing_extensions.Self: ...
904-
def __ior__(self, __value: typing_extensions.Self) -> typing_extensions.Self: ...
905+
@overload
906+
def __or__(self, __value: dict[str, Any]) -> dict[str, object]: ...
907+
@overload
908+
def __ror__(self, __value: typing_extensions.Self) -> typing_extensions.Self: ...
909+
@overload
910+
def __ror__(self, __value: dict[str, Any]) -> dict[str, object]: ...
911+
# supposedly incompatible definitions of __or__ and __ior__
912+
def __ior__(self, __value: typing_extensions.Self) -> typing_extensions.Self: ... # type: ignore[misc]
905913

906914
@_final
907915
class ForwardRef:

0 commit comments

Comments
 (0)