Skip to content

Commit a7bdffd

Browse files
Sync typeshed (#21124)
Source commit: python/typeshed@c5e47fa
1 parent 3cda6ec commit a7bdffd

File tree

15 files changed

+110
-46
lines changed

15 files changed

+110
-46
lines changed

mypy/typeshed/stdlib/_pickle.pyi

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ class PicklerMemoProxy:
6161
class Pickler:
6262
fast: bool
6363
dispatch_table: Mapping[type, Callable[[Any], _ReducedType]]
64-
reducer_override: Callable[[Any], Any]
6564
bin: bool # undocumented
6665
def __init__(
6766
self,
@@ -79,6 +78,10 @@ class Pickler:
7978

8079
# this method has no default implementation for Python < 3.13
8180
def persistent_id(self, obj: Any, /) -> Any: ...
81+
# The following method is not defined on _Pickler, but can be defined on
82+
# sub-classes. Should return `NotImplemented` if pickling the supplied
83+
# object is not supported and returns the same types as `__reduce__()`.
84+
def reducer_override(self, obj: object, /) -> _ReducedType: ...
8285

8386
@type_check_only
8487
class UnpicklerMemoProxy:

mypy/typeshed/stdlib/_sqlite3.pyi

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ from sqlite3 import (
1919
_IsolationLevel,
2020
)
2121
from typing import Any, Final, Literal, TypeVar, overload
22-
from typing_extensions import TypeAlias
22+
from typing_extensions import TypeAlias, deprecated
2323

2424
if sys.version_info >= (3, 11):
2525
from sqlite3 import Blob as Blob
@@ -299,7 +299,11 @@ def enable_callback_tracebacks(enable: bool, /) -> None: ...
299299

300300
if sys.version_info < (3, 12):
301301
# takes a pos-or-keyword argument because there is a C wrapper
302-
def enable_shared_cache(do_enable: int) -> None: ...
302+
@deprecated(
303+
"Deprecated since Python 3.10; removed in Python 3.12. "
304+
"Open database in URI mode using `cache=shared` parameter instead."
305+
)
306+
def enable_shared_cache(do_enable: int) -> None: ... # undocumented
303307

304308
if sys.version_info >= (3, 10):
305309
def register_adapter(type: type[_T], adapter: _Adapter[_T], /) -> None: ...
@@ -310,4 +314,4 @@ else:
310314
def register_converter(name: str, converter: _Converter, /) -> None: ...
311315

312316
if sys.version_info < (3, 10):
313-
OptimizedUnicode = str
317+
OptimizedUnicode = str # undocumented

mypy/typeshed/stdlib/_ssl.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ if sys.version_info < (3, 12):
5555
def RAND_pseudo_bytes(n: int, /) -> tuple[bytes, bool]: ...
5656

5757
if sys.version_info < (3, 10):
58+
@deprecated("Unsupported by OpenSSL since 1.1.1; removed in Python 3.10.")
5859
def RAND_egd(path: str) -> None: ...
5960

6061
def RAND_status() -> bool: ...
Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
1+
import sys
12
from _typeshed import StrOrBytesPath
23
from types import FrameType
34
from typing import Any
45

5-
from . import tasks
6+
from .tasks import Task
67

7-
def _task_repr_info(task: tasks.Task[Any]) -> list[str]: ... # undocumented
8-
def _task_get_stack(task: tasks.Task[Any], limit: int | None) -> list[FrameType]: ... # undocumented
9-
def _task_print_stack(task: tasks.Task[Any], limit: int | None, file: StrOrBytesPath) -> None: ... # undocumented
8+
def _task_repr_info(task: Task[Any]) -> list[str]: ... # undocumented
9+
10+
if sys.version_info >= (3, 13):
11+
def _task_repr(task: Task[Any]) -> str: ... # undocumented
12+
13+
elif sys.version_info >= (3, 11):
14+
def _task_repr(self: Task[Any]) -> str: ... # undocumented
15+
16+
def _task_get_stack(task: Task[Any], limit: int | None) -> list[FrameType]: ... # undocumented
17+
def _task_print_stack(task: Task[Any], limit: int | None, file: StrOrBytesPath) -> None: ... # undocumented

mypy/typeshed/stdlib/asyncio/unix_events.pyi

Lines changed: 54 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,35 @@ if sys.platform != "win32":
205205
def remove_child_handler(self, pid: int) -> bool: ...
206206
def attach_loop(self, loop: events.AbstractEventLoop | None) -> None: ...
207207

208+
@deprecated("Deprecated since Python 3.12; removed in Python 3.14.")
209+
class ThreadedChildWatcher(AbstractChildWatcher):
210+
def is_active(self) -> Literal[True]: ...
211+
def close(self) -> None: ...
212+
def __enter__(self) -> Self: ...
213+
def __exit__(
214+
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: types.TracebackType | None
215+
) -> None: ...
216+
def __del__(self) -> None: ...
217+
def add_child_handler(
218+
self, pid: int, callback: Callable[[int, int, Unpack[_Ts]], object], *args: Unpack[_Ts]
219+
) -> None: ...
220+
def remove_child_handler(self, pid: int) -> bool: ...
221+
def attach_loop(self, loop: events.AbstractEventLoop | None) -> None: ...
222+
223+
@deprecated("Deprecated since Python 3.12; removed in Python 3.14.")
224+
class PidfdChildWatcher(AbstractChildWatcher):
225+
def __enter__(self) -> Self: ...
226+
def __exit__(
227+
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: types.TracebackType | None
228+
) -> None: ...
229+
def is_active(self) -> bool: ...
230+
def close(self) -> None: ...
231+
def attach_loop(self, loop: events.AbstractEventLoop | None) -> None: ...
232+
def add_child_handler(
233+
self, pid: int, callback: Callable[[int, int, Unpack[_Ts]], object], *args: Unpack[_Ts]
234+
) -> None: ...
235+
def remove_child_handler(self, pid: int) -> bool: ...
236+
208237
else:
209238
class MultiLoopChildWatcher(AbstractChildWatcher):
210239
def is_active(self) -> bool: ...
@@ -219,30 +248,29 @@ if sys.platform != "win32":
219248
def remove_child_handler(self, pid: int) -> bool: ...
220249
def attach_loop(self, loop: events.AbstractEventLoop | None) -> None: ...
221250

222-
if sys.version_info < (3, 14):
223-
class ThreadedChildWatcher(AbstractChildWatcher):
224-
def is_active(self) -> Literal[True]: ...
225-
def close(self) -> None: ...
226-
def __enter__(self) -> Self: ...
227-
def __exit__(
228-
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: types.TracebackType | None
229-
) -> None: ...
230-
def __del__(self) -> None: ...
231-
def add_child_handler(
232-
self, pid: int, callback: Callable[[int, int, Unpack[_Ts]], object], *args: Unpack[_Ts]
233-
) -> None: ...
234-
def remove_child_handler(self, pid: int) -> bool: ...
235-
def attach_loop(self, loop: events.AbstractEventLoop | None) -> None: ...
251+
class ThreadedChildWatcher(AbstractChildWatcher):
252+
def is_active(self) -> Literal[True]: ...
253+
def close(self) -> None: ...
254+
def __enter__(self) -> Self: ...
255+
def __exit__(
256+
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: types.TracebackType | None
257+
) -> None: ...
258+
def __del__(self) -> None: ...
259+
def add_child_handler(
260+
self, pid: int, callback: Callable[[int, int, Unpack[_Ts]], object], *args: Unpack[_Ts]
261+
) -> None: ...
262+
def remove_child_handler(self, pid: int) -> bool: ...
263+
def attach_loop(self, loop: events.AbstractEventLoop | None) -> None: ...
236264

237-
class PidfdChildWatcher(AbstractChildWatcher):
238-
def __enter__(self) -> Self: ...
239-
def __exit__(
240-
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: types.TracebackType | None
241-
) -> None: ...
242-
def is_active(self) -> bool: ...
243-
def close(self) -> None: ...
244-
def attach_loop(self, loop: events.AbstractEventLoop | None) -> None: ...
245-
def add_child_handler(
246-
self, pid: int, callback: Callable[[int, int, Unpack[_Ts]], object], *args: Unpack[_Ts]
247-
) -> None: ...
248-
def remove_child_handler(self, pid: int) -> bool: ...
265+
class PidfdChildWatcher(AbstractChildWatcher):
266+
def __enter__(self) -> Self: ...
267+
def __exit__(
268+
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: types.TracebackType | None
269+
) -> None: ...
270+
def is_active(self) -> bool: ...
271+
def close(self) -> None: ...
272+
def attach_loop(self, loop: events.AbstractEventLoop | None) -> None: ...
273+
def add_child_handler(
274+
self, pid: int, callback: Callable[[int, int, Unpack[_Ts]], object], *args: Unpack[_Ts]
275+
) -> None: ...
276+
def remove_child_handler(self, pid: int) -> bool: ...

mypy/typeshed/stdlib/code.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class InteractiveConsole(InteractiveInterpreter):
2424
buffer: list[str] # undocumented
2525
filename: str # undocumented
2626
if sys.version_info >= (3, 13):
27+
local_exit: bool # undocumented
2728
def __init__(
2829
self, locals: dict[str, Any] | None = None, filename: str = "<console>", *, local_exit: bool = False
2930
) -> None: ...

mypy/typeshed/stdlib/configparser.pyi

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import sys
2-
from _typeshed import MaybeNone, StrOrBytesPath, SupportsWrite
2+
from _typeshed import BytesPath, GenericPath, MaybeNone, StrOrBytesPath, StrPath, SupportsWrite
33
from collections.abc import Callable, ItemsView, Iterable, Iterator, Mapping, MutableMapping, Sequence
44
from re import Pattern
5-
from typing import Any, ClassVar, Final, Literal, TypeVar, overload, type_check_only
5+
from typing import Any, AnyStr, ClassVar, Final, Literal, TypeVar, overload, type_check_only
66
from typing_extensions import TypeAlias, deprecated
77

88
if sys.version_info >= (3, 14):
@@ -269,7 +269,14 @@ class RawConfigParser(_Parser):
269269
def has_section(self, section: _SectionName) -> bool: ...
270270
def options(self, section: _SectionName) -> list[str]: ...
271271
def has_option(self, section: _SectionName, option: str) -> bool: ...
272-
def read(self, filenames: StrOrBytesPath | Iterable[StrOrBytesPath], encoding: str | None = None) -> list[str]: ...
272+
@overload
273+
def read(self, filenames: GenericPath[AnyStr], encoding: str | None = None) -> list[AnyStr]: ...
274+
@overload
275+
def read(self, filenames: Iterable[StrPath], encoding: str | None = None) -> list[str]: ...
276+
@overload
277+
def read(self, filenames: Iterable[BytesPath], encoding: str | None = None) -> list[bytes]: ...
278+
@overload
279+
def read(self, filenames: Iterable[StrOrBytesPath], encoding: str | None = None) -> list[str | bytes]: ...
273280
def read_file(self, f: Iterable[str], source: str | None = None) -> None: ...
274281
def read_string(self, string: str, source: str = "<string>") -> None: ...
275282
def read_dict(self, dictionary: Mapping[str, Mapping[str, Any]], source: str = "<dict>") -> None: ...

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ from importlib.abc import MetaPathFinder
1010
from os import PathLike
1111
from pathlib import Path
1212
from re import Pattern
13-
from typing import Any, ClassVar, Generic, NamedTuple, TypeVar, overload
13+
from typing import Any, ClassVar, Generic, NamedTuple, TypeVar, overload, type_check_only
1414
from typing_extensions import Self, TypeAlias, deprecated, disjoint_base
1515

1616
_T = TypeVar("_T")
@@ -54,6 +54,7 @@ elif sys.version_info >= (3, 11):
5454

5555
_EntryPointBase = DeprecatedTuple
5656
else:
57+
@type_check_only
5758
class _EntryPointBase(NamedTuple):
5859
name: str
5960
value: str

mypy/typeshed/stdlib/mmap.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ PAGESIZE: Final[int]
3434
@disjoint_base
3535
class mmap:
3636
if sys.platform == "win32":
37-
def __new__(self, fileno: int, length: int, tagname: str | None = None, access: int = 0, offset: int = 0) -> Self: ...
37+
def __new__(cls, fileno: int, length: int, tagname: str | None = None, access: int = 0, offset: int = 0) -> Self: ...
3838
else:
3939
if sys.version_info >= (3, 13):
4040
def __new__(

mypy/typeshed/stdlib/pickle.pyi

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,6 @@ class _Pickler:
208208
dispatch_table: Mapping[type, Callable[[Any], _ReducedType]]
209209
bin: bool # undocumented
210210
dispatch: ClassVar[dict[type, Callable[[Unpickler, Any], None]]] # undocumented, _Pickler only
211-
reducer_override: Callable[[Any], Any]
212211
def __init__(
213212
self,
214213
file: SupportsWrite[bytes],
@@ -220,6 +219,10 @@ class _Pickler:
220219
def dump(self, obj: Any) -> None: ...
221220
def clear_memo(self) -> None: ...
222221
def persistent_id(self, obj: Any) -> Any: ...
222+
# The following method is not defined on _Pickler, but can be defined on
223+
# sub-classes. Should return `NotImplemented` if pickling the supplied
224+
# object is not supported and returns the same types as `__reduce__()`.
225+
def reducer_override(self, obj: object, /) -> _ReducedType: ...
223226

224227
class _Unpickler:
225228
dispatch: ClassVar[dict[int, Callable[[Unpickler], None]]] # undocumented, _Unpickler only

0 commit comments

Comments
 (0)