Skip to content

Commit 2006d1c

Browse files
Add more Python 3.15 stdlib updates (#15747)
1 parent 669d5cb commit 2006d1c

10 files changed

Lines changed: 132 additions & 35 deletions

File tree

stdlib/@tests/stubtest_allowlists/py315.txt

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ _frozen_importlib_external.SourceFileLoader.source_to_code
1212
_frozen_importlib_external.SourceLoader.source_to_code
1313
_frozen_importlib_external._LoaderBasics.load_module
1414
_frozen_importlib_external.cache_from_source
15-
_interpqueues.create
16-
_interpqueues.put
1715
_pyrepl.base_eventqueue
1816
_pyrepl.commands
1917
_pyrepl.completing_reader
@@ -62,8 +60,6 @@ codecs.namereplace_errors
6260
codecs.replace_errors
6361
codecs.strict_errors
6462
codecs.xmlcharrefreplace_errors
65-
collections.Counter.__ixor__
66-
collections.Counter.__xor__
6763
concurrent.interpreters._crossinterp.UNBOUND_ERROR
6864
concurrent.interpreters._crossinterp.UNBOUND_REMOVE
6965
concurrent.interpreters._crossinterp.UnboundItem.singleton
@@ -132,7 +128,6 @@ marshal.dump
132128
marshal.dumps
133129
multiprocessing.context.BaseContext.set_forkserver_preload
134130
multiprocessing.forkserver.ForkServer.set_forkserver_preload
135-
multiprocessing.forkserver.main
136131
multiprocessing.managers.BaseListProxy.clear
137132
multiprocessing.managers.BaseListProxy.copy
138133
multiprocessing.managers._BaseDictProxy.__iter__
@@ -202,18 +197,8 @@ sre_parse
202197
symtable.symtable
203198
sys.__jit
204199
sys._monitoring
205-
sys.abi_info
206-
sys.get_lazy_imports
207-
sys.get_lazy_imports_filter
208200
sys.last_exc
209-
sys.lazy_modules
210-
sys.set_lazy_imports
211-
sys.set_lazy_imports_filter
212201
threading.Condition.locked
213-
threading.__all__
214-
threading.concurrent_tee
215-
threading.serialize_iterator
216-
threading.synchronized_iterator
217202
tkinter.Grid.content
218203
tkinter.Grid.grid_content
219204
tkinter.Image.__iter__
@@ -230,20 +215,13 @@ tkinter.Text.search
230215
tkinter.Text.search_all
231216
tkinter.font.Font.__iter__
232217
tkinter.simpledialog.__all__
233-
types.AsyncGeneratorType.ag_state
234-
types.CodeType.co_lnotab
235-
types.CoroutineType.cr_state
236-
types.FrameLocalsProxyType
237-
types.GeneratorType.gi_state
238-
types.LazyImportType
239218
types.MappingProxyType.get
240219
types.SimpleNamespace.__delattr__
241220
types.SimpleNamespace.__setattr__
242221
types.UnionType.__class_getitem__
243222
types.UnionType.__mro_entries__
244223
types.UnionType.__name__
245224
types.UnionType.__qualname__
246-
types.__all__
247225
typing.LiteralString
248226
typing.NewType.__mro_entries__
249227
typing.ParamSpec.__mro_entries__
@@ -266,6 +244,4 @@ urllib.parse.urlsplit
266244
urllib.parse.urlunparse
267245
urllib.parse.urlunsplit
268246
xml.etree.ElementTree.__all__
269-
xml.is_valid_name
270-
xml.utils
271247
zipimport.zipimporter.load_module

stdlib/VERSIONS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ wsgiref: 3.0-
336336
wsgiref.types: 3.11-
337337
xdrlib: 3.0-3.12
338338
xml: 3.0-
339+
xml.utils: 3.15-
339340
xmlrpc: 3.0-
340341
xxlimited: 3.2-
341342
zipapp: 3.5-

stdlib/_interpqueues.pyi

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import sys
12
from typing import Any, Literal, SupportsIndex, TypeAlias
23

34
_UnboundOp: TypeAlias = Literal[1, 2, 3]
@@ -6,13 +7,25 @@ class QueueError(RuntimeError): ...
67
class QueueNotFoundError(QueueError): ...
78

89
def bind(qid: SupportsIndex) -> None: ...
9-
def create(maxsize: SupportsIndex, fmt: SupportsIndex, unboundop: _UnboundOp) -> int: ...
10+
11+
if sys.version_info >= (3, 15):
12+
def create(maxsize: SupportsIndex, unboundop: SupportsIndex = -1, fallback: SupportsIndex = -1) -> int: ...
13+
14+
else:
15+
def create(maxsize: SupportsIndex, fmt: SupportsIndex, unboundop: _UnboundOp) -> int: ...
16+
1017
def destroy(qid: SupportsIndex) -> None: ...
1118
def get(qid: SupportsIndex) -> tuple[Any, int, _UnboundOp | None]: ...
1219
def get_count(qid: SupportsIndex) -> int: ...
1320
def get_maxsize(qid: SupportsIndex) -> int: ...
1421
def get_queue_defaults(qid: SupportsIndex) -> tuple[int, _UnboundOp]: ...
1522
def is_full(qid: SupportsIndex) -> bool: ...
1623
def list_all() -> list[tuple[int, int, _UnboundOp]]: ...
17-
def put(qid: SupportsIndex, obj: Any, fmt: SupportsIndex, unboundop: _UnboundOp) -> None: ...
24+
25+
if sys.version_info >= (3, 15):
26+
def put(qid: SupportsIndex, obj: Any, unboundop: SupportsIndex = -1, fallback: SupportsIndex = -1) -> None: ...
27+
28+
else:
29+
def put(qid: SupportsIndex, obj: Any, fmt: SupportsIndex, unboundop: _UnboundOp) -> None: ...
30+
1831
def release(qid: SupportsIndex) -> None: ...

stdlib/collections/__init__.pyi

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,13 +315,18 @@ class Counter(dict[_T, int], Generic[_T]):
315315
def __sub__(self, other: Counter[_T]) -> Counter[_T]: ...
316316
def __and__(self, other: Counter[_T]) -> Counter[_T]: ...
317317
def __or__(self, other: Counter[_S]) -> Counter[_T | _S]: ... # type: ignore[override]
318+
if sys.version_info >= (3, 15):
319+
def __xor__(self, other: Counter[_S]) -> Counter[_T | _S]: ... # type: ignore[override]
320+
318321
def __pos__(self) -> Counter[_T]: ...
319322
def __neg__(self) -> Counter[_T]: ...
320323
# several type: ignores because __iadd__ is supposedly incompatible with __add__, etc.
321324
def __iadd__(self, other: SupportsItems[_T, int]) -> Self: ... # type: ignore[misc]
322325
def __isub__(self, other: SupportsItems[_T, int]) -> Self: ...
323326
def __iand__(self, other: SupportsItems[_T, int]) -> Self: ...
324327
def __ior__(self, other: SupportsItems[_T, int]) -> Self: ... # type: ignore[override,misc]
328+
if sys.version_info >= (3, 15):
329+
def __ixor__(self, other: Counter[_T]) -> Self: ... # type: ignore[misc]
325330

326331
# The pure-Python implementations of the "views" classes
327332
# These are exposed at runtime in `collections/__init__.py`

stdlib/multiprocessing/forkserver.pyi

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,20 @@ class ForkServer:
1515
def connect_to_new_process(self, fds: Sequence[int]) -> tuple[int, int]: ...
1616
def ensure_running(self) -> None: ...
1717

18-
if sys.version_info >= (3, 14):
18+
if sys.version_info >= (3, 15):
19+
def main(
20+
listener_fd: int | None,
21+
alive_r: FileDescriptorLike,
22+
preload: Sequence[str],
23+
main_path: str | None = None,
24+
sys_path: list[str] | None = None,
25+
*,
26+
sys_argv: list[str] | None = None,
27+
authkey_r: int | None = None,
28+
on_error: str = "ignore",
29+
) -> None: ...
30+
31+
elif sys.version_info >= (3, 14):
1932
# `sys_argv` parameter added in Python 3.14.3
2033
def main(
2134
listener_fd: int | None,

stdlib/sys/__init__.pyi

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,30 @@ from _typeshed.importlib import MetaPathFinderProtocol, PathEntryFinderProtocol
44
from builtins import object as _object
55
from collections.abc import AsyncGenerator, Callable, Sequence
66
from io import TextIOWrapper
7-
from types import FrameType, ModuleType, TracebackType
7+
from types import FrameType, ModuleType, SimpleNamespace, TracebackType
88
from typing import Any, Final, Literal, NoReturn, Protocol, TextIO, TypeAlias, TypeVar, final, overload, type_check_only
99
from typing_extensions import LiteralString, deprecated
1010

1111
_T = TypeVar("_T")
12+
_LazyImportMode: TypeAlias = Literal["normal", "all", "none"]
13+
_LazyImportFilter: TypeAlias = Callable[[str, str, tuple[str, ...] | None], bool]
1214

1315
# see https://github.com/python/typeshed/issues/8513#issue-1333671093 for the rationale behind this alias
1416
_ExitCode: TypeAlias = str | int | None
1517

18+
if sys.version_info >= (3, 15):
19+
@type_check_only
20+
class _AbiInfo(SimpleNamespace):
21+
pointer_bits: int
22+
free_threaded: bool
23+
debug: bool
24+
byteorder: Literal["little", "big"]
25+
1626
# ----- sys variables -----
1727
if sys.platform != "win32":
1828
abiflags: str
29+
if sys.version_info >= (3, 15):
30+
abi_info: _AbiInfo
1931
argv: list[str]
2032
base_exec_prefix: str
2133
base_prefix: str
@@ -40,6 +52,8 @@ maxsize: int
4052
maxunicode: int
4153
meta_path: list[MetaPathFinderProtocol]
4254
modules: dict[str, ModuleType]
55+
if sys.version_info >= (3, 15):
56+
lazy_modules: dict[str, set[str]]
4357
orig_argv: list[str]
4458
path: list[str]
4559
path_hooks: list[Callable[[str], PathEntryFinderProtocol]]
@@ -376,6 +390,11 @@ if sys.platform != "win32":
376390

377391
def getfilesystemencoding() -> LiteralString: ...
378392
def getfilesystemencodeerrors() -> LiteralString: ...
393+
394+
if sys.version_info >= (3, 15):
395+
def get_lazy_imports() -> _LazyImportMode: ...
396+
def get_lazy_imports_filter() -> _LazyImportFilter | None: ...
397+
379398
def getrefcount(object: Any, /) -> int: ...
380399
def getrecursionlimit() -> int: ...
381400
def getsizeof(obj: object, default: int = ...) -> int: ...
@@ -486,6 +505,10 @@ def set_coroutine_origin_tracking_depth(depth: int) -> None: ...
486505
def set_int_max_str_digits(maxdigits: int) -> None: ...
487506
def get_int_max_str_digits() -> int: ...
488507

508+
if sys.version_info >= (3, 15):
509+
def set_lazy_imports(mode: _LazyImportMode) -> None: ...
510+
def set_lazy_imports_filter(filter: _LazyImportFilter | None) -> None: ...
511+
489512
if sys.version_info >= (3, 12):
490513
if sys.version_info >= (3, 13):
491514
def getunicodeinternedsize(*, _only_immortal: bool = False) -> int: ...

stdlib/threading.pyi

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import _thread
22
import sys
33
from _thread import _ExceptHookArgs, get_native_id as get_native_id
44
from _typeshed import ProfileFunction, TraceFunction
5-
from collections.abc import Callable, Iterable, Mapping
5+
from collections.abc import Callable, Iterable, Iterator, Mapping
66
from contextvars import Context
77
from types import TracebackType
88
from typing import Any, Final, TypeVar, final
9-
from typing_extensions import deprecated
9+
from typing_extensions import Self, deprecated
1010

1111
_T = TypeVar("_T")
1212

@@ -42,6 +42,9 @@ __all__ = [
4242
if sys.version_info >= (3, 12):
4343
__all__ += ["setprofile_all_threads", "settrace_all_threads"]
4444

45+
if sys.version_info >= (3, 15):
46+
__all__ += ["concurrent_tee", "serialize_iterator", "synchronized_iterator"]
47+
4548
_profile_hook: ProfileFunction | None
4649

4750
def active_count() -> int: ...
@@ -62,6 +65,20 @@ if sys.version_info >= (3, 12):
6265

6366
def gettrace() -> TraceFunction | None: ...
6467
def getprofile() -> ProfileFunction | None: ...
68+
69+
if sys.version_info >= (3, 15):
70+
@final
71+
class serialize_iterator(Iterator[_T]):
72+
def __init__(self, iterable: Iterable[_T]) -> None: ...
73+
def __iter__(self) -> Self: ...
74+
def __next__(self) -> _T: ...
75+
def send(self, value: Any, /) -> _T: ...
76+
def throw(self, typ: type[BaseException], val: BaseException | object = ..., tb: TracebackType | None = ...) -> _T: ...
77+
def close(self) -> None: ...
78+
79+
def synchronized_iterator(func: Callable[..., Iterable[_T]]) -> Callable[..., Iterator[_T]]: ...
80+
def concurrent_tee(iterable: Iterable[_T], n: int = 2) -> tuple[Iterator[_T], ...]: ...
81+
6582
def stack_size(size: int = 0, /) -> int: ...
6683

6784
TIMEOUT_MAX: Final[float]

stdlib/types.pyi

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ from collections.abc import (
1212
Iterator,
1313
KeysView,
1414
Mapping,
15+
MutableMapping,
1516
MutableSequence,
1617
ValuesView,
1718
)
@@ -62,6 +63,9 @@ if sys.version_info >= (3, 12):
6263
if sys.version_info >= (3, 13):
6364
__all__ += ["CapsuleType"]
6465

66+
if sys.version_info >= (3, 15):
67+
__all__ += ["FrameLocalsProxyType", "LazyImportType"]
68+
6569
# Note, all classes "defined" here require special handling.
6670

6771
_T1 = TypeVar("_T1")
@@ -149,9 +153,11 @@ class CodeType:
149153
def co_name(self) -> str: ...
150154
@property
151155
def co_firstlineno(self) -> int: ...
152-
@property
153-
@deprecated("Deprecated since Python 3.10; will be removed in Python 3.15. Use `CodeType.co_lines()` instead.")
154-
def co_lnotab(self) -> bytes: ...
156+
if sys.version_info < (3, 15):
157+
@property
158+
@deprecated("Deprecated since Python 3.10; will be removed in Python 3.15. Use `CodeType.co_lines()` instead.")
159+
def co_lnotab(self) -> bytes: ...
160+
155161
@property
156162
def co_freevars(self) -> tuple[str, ...]: ...
157163
@property
@@ -360,6 +366,9 @@ class GeneratorType(Generator[_YieldT_co, _SendT_contra, _ReturnT_co]):
360366
if sys.version_info >= (3, 11):
361367
@property
362368
def gi_suspended(self) -> bool: ...
369+
if sys.version_info >= (3, 15):
370+
@property
371+
def gi_state(self) -> Literal["GEN_CREATED", "GEN_SUSPENDED", "GEN_RUNNING", "GEN_CLOSED"]: ...
363372
__name__: str
364373
__qualname__: str
365374
def __iter__(self) -> Self: ...
@@ -389,6 +398,9 @@ class AsyncGeneratorType(AsyncGenerator[_YieldT_co, _SendT_contra]):
389398
if sys.version_info >= (3, 12):
390399
@property
391400
def ag_suspended(self) -> bool: ...
401+
if sys.version_info >= (3, 15):
402+
@property
403+
def ag_state(self) -> Literal["AGEN_CREATED", "AGEN_SUSPENDED", "AGEN_RUNNING", "AGEN_CLOSED"]: ...
392404

393405
def __aiter__(self) -> Self: ...
394406
def __anext__(self) -> Coroutine[Any, Any, _YieldT_co]: ...
@@ -423,6 +435,9 @@ class CoroutineType(Coroutine[_YieldT_co, _SendT_nd_contra, _ReturnT_nd_co]):
423435
if sys.version_info >= (3, 11):
424436
@property
425437
def cr_suspended(self) -> bool: ...
438+
if sys.version_info >= (3, 15):
439+
@property
440+
def cr_state(self) -> Literal["CORO_CREATED", "CORO_SUSPENDED", "CORO_RUNNING", "CORO_CLOSED"]: ...
426441

427442
def close(self) -> None: ...
428443
def __await__(self) -> Generator[Any, None, _ReturnT_nd_co]: ...
@@ -552,8 +567,12 @@ class FrameType:
552567
# An `int | None` annotation here causes too many false-positive errors, so applying `int | Any`.
553568
@property
554569
def f_lineno(self) -> int | MaybeNone: ...
555-
@property
556-
def f_locals(self) -> dict[str, Any]: ...
570+
if sys.version_info >= (3, 15):
571+
@property
572+
def f_locals(self) -> FrameLocalsProxyType | dict[str, Any]: ...
573+
else:
574+
@property
575+
def f_locals(self) -> dict[str, Any]: ...
557576
f_trace: Callable[[FrameType, str, Any], Any] | None
558577
f_trace_lines: bool
559578
f_trace_opcodes: bool
@@ -562,6 +581,28 @@ class FrameType:
562581
@property
563582
def f_generator(self) -> GeneratorType[Any, Any, Any] | CoroutineType[Any, Any, Any] | None: ...
564583

584+
if sys.version_info >= (3, 15):
585+
@final
586+
class FrameLocalsProxyType(MutableMapping[str, Any]):
587+
def __new__(cls, frame: FrameType, /) -> Self: ...
588+
def __getitem__(self, key: str, /) -> Any: ...
589+
def __setitem__(self, key: str, value: Any, /) -> None: ...
590+
def __delitem__(self, key: str, /) -> None: ...
591+
def __iter__(self) -> Iterator[str]: ...
592+
def __len__(self) -> int: ...
593+
def __contains__(self, key: object, /) -> bool: ...
594+
def __reversed__(self) -> Iterator[str]: ...
595+
def copy(self) -> dict[str, Any]: ...
596+
def pop(self, key: str, default: Any = ..., /) -> Any: ...
597+
def setdefault(self, key: str, default: Any = ..., /) -> Any: ...
598+
def update(self, object: SupportsKeysAndGetItem[str, Any] | Iterable[tuple[str, Any]], /) -> None: ... # type: ignore[override]
599+
600+
@final
601+
class LazyImportType:
602+
@property
603+
def __name__(self) -> str: ...
604+
def resolve(self) -> Any: ...
605+
565606
@final
566607
class GetSetDescriptorType:
567608
@property

stdlib/xml/__init__.pyi

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
# At runtime, listing submodules in __all__ without them being imported is
22
# valid, and causes them to be included in a star import. See #6523
3+
import sys
4+
35
__all__ = ["dom", "parsers", "sax", "etree"] # noqa: F822 # pyright: ignore[reportUnsupportedDunderAll]
6+
7+
if sys.version_info >= (3, 15):
8+
__all__ += ["is_valid_name"] # pyright: ignore[reportUnsupportedDunderAll]
9+
from xml.utils import is_valid_name as is_valid_name, is_valid_text as is_valid_text

stdlib/xml/utils.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def is_valid_name(name: str) -> bool: ...
2+
def is_valid_text(data: str) -> bool: ...

0 commit comments

Comments
 (0)