Sync typeshed (#21124)
Source commit:
https://github.com/python/typeshed/commit/c5e47faeda2cf9d233f91bc1dc95814b0cc7ccba
diff --git a/mypy/typeshed/stdlib/_pickle.pyi b/mypy/typeshed/stdlib/_pickle.pyi
index 544f787..4294de4 100644
--- a/mypy/typeshed/stdlib/_pickle.pyi
+++ b/mypy/typeshed/stdlib/_pickle.pyi
@@ -61,7 +61,6 @@
class Pickler:
fast: bool
dispatch_table: Mapping[type, Callable[[Any], _ReducedType]]
- reducer_override: Callable[[Any], Any]
bin: bool # undocumented
def __init__(
self,
@@ -79,6 +78,10 @@
# this method has no default implementation for Python < 3.13
def persistent_id(self, obj: Any, /) -> Any: ...
+ # The following method is not defined on _Pickler, but can be defined on
+ # sub-classes. Should return `NotImplemented` if pickling the supplied
+ # object is not supported and returns the same types as `__reduce__()`.
+ def reducer_override(self, obj: object, /) -> _ReducedType: ...
@type_check_only
class UnpicklerMemoProxy:
diff --git a/mypy/typeshed/stdlib/_sqlite3.pyi b/mypy/typeshed/stdlib/_sqlite3.pyi
index 50006dc..437a9c9 100644
--- a/mypy/typeshed/stdlib/_sqlite3.pyi
+++ b/mypy/typeshed/stdlib/_sqlite3.pyi
@@ -19,7 +19,7 @@
_IsolationLevel,
)
from typing import Any, Final, Literal, TypeVar, overload
-from typing_extensions import TypeAlias
+from typing_extensions import TypeAlias, deprecated
if sys.version_info >= (3, 11):
from sqlite3 import Blob as Blob
@@ -299,7 +299,11 @@
if sys.version_info < (3, 12):
# takes a pos-or-keyword argument because there is a C wrapper
- def enable_shared_cache(do_enable: int) -> None: ...
+ @deprecated(
+ "Deprecated since Python 3.10; removed in Python 3.12. "
+ "Open database in URI mode using `cache=shared` parameter instead."
+ )
+ def enable_shared_cache(do_enable: int) -> None: ... # undocumented
if sys.version_info >= (3, 10):
def register_adapter(type: type[_T], adapter: _Adapter[_T], /) -> None: ...
@@ -310,4 +314,4 @@
def register_converter(name: str, converter: _Converter, /) -> None: ...
if sys.version_info < (3, 10):
- OptimizedUnicode = str
+ OptimizedUnicode = str # undocumented
diff --git a/mypy/typeshed/stdlib/_ssl.pyi b/mypy/typeshed/stdlib/_ssl.pyi
index 73a43f2..d8cb9d4 100644
--- a/mypy/typeshed/stdlib/_ssl.pyi
+++ b/mypy/typeshed/stdlib/_ssl.pyi
@@ -55,6 +55,7 @@
def RAND_pseudo_bytes(n: int, /) -> tuple[bytes, bool]: ...
if sys.version_info < (3, 10):
+ @deprecated("Unsupported by OpenSSL since 1.1.1; removed in Python 3.10.")
def RAND_egd(path: str) -> None: ...
def RAND_status() -> bool: ...
diff --git a/mypy/typeshed/stdlib/asyncio/base_tasks.pyi b/mypy/typeshed/stdlib/asyncio/base_tasks.pyi
index 42e952f..5b010a9 100644
--- a/mypy/typeshed/stdlib/asyncio/base_tasks.pyi
+++ b/mypy/typeshed/stdlib/asyncio/base_tasks.pyi
@@ -1,9 +1,17 @@
+import sys
from _typeshed import StrOrBytesPath
from types import FrameType
from typing import Any
-from . import tasks
+from .tasks import Task
-def _task_repr_info(task: tasks.Task[Any]) -> list[str]: ... # undocumented
-def _task_get_stack(task: tasks.Task[Any], limit: int | None) -> list[FrameType]: ... # undocumented
-def _task_print_stack(task: tasks.Task[Any], limit: int | None, file: StrOrBytesPath) -> None: ... # undocumented
+def _task_repr_info(task: Task[Any]) -> list[str]: ... # undocumented
+
+if sys.version_info >= (3, 13):
+ def _task_repr(task: Task[Any]) -> str: ... # undocumented
+
+elif sys.version_info >= (3, 11):
+ def _task_repr(self: Task[Any]) -> str: ... # undocumented
+
+def _task_get_stack(task: Task[Any], limit: int | None) -> list[FrameType]: ... # undocumented
+def _task_print_stack(task: Task[Any], limit: int | None, file: StrOrBytesPath) -> None: ... # undocumented
diff --git a/mypy/typeshed/stdlib/asyncio/unix_events.pyi b/mypy/typeshed/stdlib/asyncio/unix_events.pyi
index 9071ee9..54a2a03 100644
--- a/mypy/typeshed/stdlib/asyncio/unix_events.pyi
+++ b/mypy/typeshed/stdlib/asyncio/unix_events.pyi
@@ -205,6 +205,35 @@
def remove_child_handler(self, pid: int) -> bool: ...
def attach_loop(self, loop: events.AbstractEventLoop | None) -> None: ...
+ @deprecated("Deprecated since Python 3.12; removed in Python 3.14.")
+ class ThreadedChildWatcher(AbstractChildWatcher):
+ def is_active(self) -> Literal[True]: ...
+ def close(self) -> None: ...
+ def __enter__(self) -> Self: ...
+ def __exit__(
+ self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: types.TracebackType | None
+ ) -> None: ...
+ def __del__(self) -> None: ...
+ def add_child_handler(
+ self, pid: int, callback: Callable[[int, int, Unpack[_Ts]], object], *args: Unpack[_Ts]
+ ) -> None: ...
+ def remove_child_handler(self, pid: int) -> bool: ...
+ def attach_loop(self, loop: events.AbstractEventLoop | None) -> None: ...
+
+ @deprecated("Deprecated since Python 3.12; removed in Python 3.14.")
+ class PidfdChildWatcher(AbstractChildWatcher):
+ def __enter__(self) -> Self: ...
+ def __exit__(
+ self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: types.TracebackType | None
+ ) -> None: ...
+ def is_active(self) -> bool: ...
+ def close(self) -> None: ...
+ def attach_loop(self, loop: events.AbstractEventLoop | None) -> None: ...
+ def add_child_handler(
+ self, pid: int, callback: Callable[[int, int, Unpack[_Ts]], object], *args: Unpack[_Ts]
+ ) -> None: ...
+ def remove_child_handler(self, pid: int) -> bool: ...
+
else:
class MultiLoopChildWatcher(AbstractChildWatcher):
def is_active(self) -> bool: ...
@@ -219,30 +248,29 @@
def remove_child_handler(self, pid: int) -> bool: ...
def attach_loop(self, loop: events.AbstractEventLoop | None) -> None: ...
- if sys.version_info < (3, 14):
- class ThreadedChildWatcher(AbstractChildWatcher):
- def is_active(self) -> Literal[True]: ...
- def close(self) -> None: ...
- def __enter__(self) -> Self: ...
- def __exit__(
- self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: types.TracebackType | None
- ) -> None: ...
- def __del__(self) -> None: ...
- def add_child_handler(
- self, pid: int, callback: Callable[[int, int, Unpack[_Ts]], object], *args: Unpack[_Ts]
- ) -> None: ...
- def remove_child_handler(self, pid: int) -> bool: ...
- def attach_loop(self, loop: events.AbstractEventLoop | None) -> None: ...
+ class ThreadedChildWatcher(AbstractChildWatcher):
+ def is_active(self) -> Literal[True]: ...
+ def close(self) -> None: ...
+ def __enter__(self) -> Self: ...
+ def __exit__(
+ self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: types.TracebackType | None
+ ) -> None: ...
+ def __del__(self) -> None: ...
+ def add_child_handler(
+ self, pid: int, callback: Callable[[int, int, Unpack[_Ts]], object], *args: Unpack[_Ts]
+ ) -> None: ...
+ def remove_child_handler(self, pid: int) -> bool: ...
+ def attach_loop(self, loop: events.AbstractEventLoop | None) -> None: ...
- class PidfdChildWatcher(AbstractChildWatcher):
- def __enter__(self) -> Self: ...
- def __exit__(
- self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: types.TracebackType | None
- ) -> None: ...
- def is_active(self) -> bool: ...
- def close(self) -> None: ...
- def attach_loop(self, loop: events.AbstractEventLoop | None) -> None: ...
- def add_child_handler(
- self, pid: int, callback: Callable[[int, int, Unpack[_Ts]], object], *args: Unpack[_Ts]
- ) -> None: ...
- def remove_child_handler(self, pid: int) -> bool: ...
+ class PidfdChildWatcher(AbstractChildWatcher):
+ def __enter__(self) -> Self: ...
+ def __exit__(
+ self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: types.TracebackType | None
+ ) -> None: ...
+ def is_active(self) -> bool: ...
+ def close(self) -> None: ...
+ def attach_loop(self, loop: events.AbstractEventLoop | None) -> None: ...
+ def add_child_handler(
+ self, pid: int, callback: Callable[[int, int, Unpack[_Ts]], object], *args: Unpack[_Ts]
+ ) -> None: ...
+ def remove_child_handler(self, pid: int) -> bool: ...
diff --git a/mypy/typeshed/stdlib/code.pyi b/mypy/typeshed/stdlib/code.pyi
index 0b13c8a..478d5aa 100644
--- a/mypy/typeshed/stdlib/code.pyi
+++ b/mypy/typeshed/stdlib/code.pyi
@@ -24,6 +24,7 @@
buffer: list[str] # undocumented
filename: str # undocumented
if sys.version_info >= (3, 13):
+ local_exit: bool # undocumented
def __init__(
self, locals: dict[str, Any] | None = None, filename: str = "<console>", *, local_exit: bool = False
) -> None: ...
diff --git a/mypy/typeshed/stdlib/configparser.pyi b/mypy/typeshed/stdlib/configparser.pyi
index 1909d80..1e11088 100644
--- a/mypy/typeshed/stdlib/configparser.pyi
+++ b/mypy/typeshed/stdlib/configparser.pyi
@@ -1,8 +1,8 @@
import sys
-from _typeshed import MaybeNone, StrOrBytesPath, SupportsWrite
+from _typeshed import BytesPath, GenericPath, MaybeNone, StrOrBytesPath, StrPath, SupportsWrite
from collections.abc import Callable, ItemsView, Iterable, Iterator, Mapping, MutableMapping, Sequence
from re import Pattern
-from typing import Any, ClassVar, Final, Literal, TypeVar, overload, type_check_only
+from typing import Any, AnyStr, ClassVar, Final, Literal, TypeVar, overload, type_check_only
from typing_extensions import TypeAlias, deprecated
if sys.version_info >= (3, 14):
@@ -269,7 +269,14 @@
def has_section(self, section: _SectionName) -> bool: ...
def options(self, section: _SectionName) -> list[str]: ...
def has_option(self, section: _SectionName, option: str) -> bool: ...
- def read(self, filenames: StrOrBytesPath | Iterable[StrOrBytesPath], encoding: str | None = None) -> list[str]: ...
+ @overload
+ def read(self, filenames: GenericPath[AnyStr], encoding: str | None = None) -> list[AnyStr]: ...
+ @overload
+ def read(self, filenames: Iterable[StrPath], encoding: str | None = None) -> list[str]: ...
+ @overload
+ def read(self, filenames: Iterable[BytesPath], encoding: str | None = None) -> list[bytes]: ...
+ @overload
+ def read(self, filenames: Iterable[StrOrBytesPath], encoding: str | None = None) -> list[str | bytes]: ...
def read_file(self, f: Iterable[str], source: str | None = None) -> None: ...
def read_string(self, string: str, source: str = "<string>") -> None: ...
def read_dict(self, dictionary: Mapping[str, Mapping[str, Any]], source: str = "<dict>") -> None: ...
diff --git a/mypy/typeshed/stdlib/importlib/metadata/__init__.pyi b/mypy/typeshed/stdlib/importlib/metadata/__init__.pyi
index 9286e92..bb1b22f 100644
--- a/mypy/typeshed/stdlib/importlib/metadata/__init__.pyi
+++ b/mypy/typeshed/stdlib/importlib/metadata/__init__.pyi
@@ -10,7 +10,7 @@
from os import PathLike
from pathlib import Path
from re import Pattern
-from typing import Any, ClassVar, Generic, NamedTuple, TypeVar, overload
+from typing import Any, ClassVar, Generic, NamedTuple, TypeVar, overload, type_check_only
from typing_extensions import Self, TypeAlias, deprecated, disjoint_base
_T = TypeVar("_T")
@@ -54,6 +54,7 @@
_EntryPointBase = DeprecatedTuple
else:
+ @type_check_only
class _EntryPointBase(NamedTuple):
name: str
value: str
diff --git a/mypy/typeshed/stdlib/mmap.pyi b/mypy/typeshed/stdlib/mmap.pyi
index 005020b..12425f7 100644
--- a/mypy/typeshed/stdlib/mmap.pyi
+++ b/mypy/typeshed/stdlib/mmap.pyi
@@ -34,7 +34,7 @@
@disjoint_base
class mmap:
if sys.platform == "win32":
- def __new__(self, fileno: int, length: int, tagname: str | None = None, access: int = 0, offset: int = 0) -> Self: ...
+ def __new__(cls, fileno: int, length: int, tagname: str | None = None, access: int = 0, offset: int = 0) -> Self: ...
else:
if sys.version_info >= (3, 13):
def __new__(
diff --git a/mypy/typeshed/stdlib/pickle.pyi b/mypy/typeshed/stdlib/pickle.pyi
index 0f486b1..03ba6c1 100644
--- a/mypy/typeshed/stdlib/pickle.pyi
+++ b/mypy/typeshed/stdlib/pickle.pyi
@@ -208,7 +208,6 @@
dispatch_table: Mapping[type, Callable[[Any], _ReducedType]]
bin: bool # undocumented
dispatch: ClassVar[dict[type, Callable[[Unpickler, Any], None]]] # undocumented, _Pickler only
- reducer_override: Callable[[Any], Any]
def __init__(
self,
file: SupportsWrite[bytes],
@@ -220,6 +219,10 @@
def dump(self, obj: Any) -> None: ...
def clear_memo(self) -> None: ...
def persistent_id(self, obj: Any) -> Any: ...
+ # The following method is not defined on _Pickler, but can be defined on
+ # sub-classes. Should return `NotImplemented` if pickling the supplied
+ # object is not supported and returns the same types as `__reduce__()`.
+ def reducer_override(self, obj: object, /) -> _ReducedType: ...
class _Unpickler:
dispatch: ClassVar[dict[int, Callable[[Unpickler], None]]] # undocumented, _Unpickler only
diff --git a/mypy/typeshed/stdlib/signal.pyi b/mypy/typeshed/stdlib/signal.pyi
index c2668bd..3bf1d31 100644
--- a/mypy/typeshed/stdlib/signal.pyi
+++ b/mypy/typeshed/stdlib/signal.pyi
@@ -9,7 +9,6 @@
NSIG: int
class Signals(IntEnum):
- SIGABRT = 6
SIGFPE = 8
SIGILL = 4
SIGINT = 2
@@ -17,10 +16,12 @@
SIGTERM = 15
if sys.platform == "win32":
+ SIGABRT = 22
SIGBREAK = 21
CTRL_C_EVENT = 0
CTRL_BREAK_EVENT = 1
else:
+ SIGABRT = 6
SIGALRM = 14
SIGBUS = 7
SIGCHLD = 17
diff --git a/mypy/typeshed/stdlib/statistics.pyi b/mypy/typeshed/stdlib/statistics.pyi
index 188bed3..d9f282b 100644
--- a/mypy/typeshed/stdlib/statistics.pyi
+++ b/mypy/typeshed/stdlib/statistics.pyi
@@ -3,7 +3,7 @@
from collections.abc import Callable, Hashable, Iterable, Sequence, Sized
from decimal import Decimal
from fractions import Fraction
-from typing import Literal, NamedTuple, Protocol, SupportsFloat, SupportsIndex, TypeVar
+from typing import Literal, NamedTuple, Protocol, SupportsFloat, SupportsIndex, TypeVar, type_check_only
from typing_extensions import Self, TypeAlias
__all__ = [
@@ -44,7 +44,9 @@
# Used in linear_regression
_T_co = TypeVar("_T_co", covariant=True)
+@type_check_only
class _SizedIterable(Iterable[_T_co], Sized, Protocol[_T_co]): ...
+
class StatisticsError(ValueError): ...
if sys.version_info >= (3, 11):
diff --git a/mypy/typeshed/stdlib/threading.pyi b/mypy/typeshed/stdlib/threading.pyi
index abc7fe7..03c8865 100644
--- a/mypy/typeshed/stdlib/threading.pyi
+++ b/mypy/typeshed/stdlib/threading.pyi
@@ -3,7 +3,7 @@
from _thread import _ExceptHookArgs, get_native_id as get_native_id
from _typeshed import ProfileFunction, TraceFunction
from collections.abc import Callable, Iterable, Mapping
-from contextvars import ContextVar
+from contextvars import Context
from types import TracebackType
from typing import Any, Final, TypeVar, final
from typing_extensions import deprecated
@@ -87,7 +87,7 @@
kwargs: Mapping[str, Any] | None = None,
*,
daemon: bool | None = None,
- context: ContextVar[Any] | None = None,
+ context: Context | None = None,
) -> None: ...
else:
def __init__(
diff --git a/mypy/typeshed/stdlib/tkinter/ttk.pyi b/mypy/typeshed/stdlib/tkinter/ttk.pyi
index 7143c7c..0a68372 100644
--- a/mypy/typeshed/stdlib/tkinter/ttk.pyi
+++ b/mypy/typeshed/stdlib/tkinter/ttk.pyi
@@ -57,6 +57,7 @@
_P = ParamSpec("_P")
_T = TypeVar("_T")
+@type_check_only
class _Layout(TypedDict, total=False):
side: Literal["left", "right", "top", "bottom"]
sticky: str # consists of letters 'n', 's', 'w', 'e', may contain repeats, may be empty
@@ -68,6 +69,7 @@
_LayoutSpec: TypeAlias = list[tuple[str, _Layout | None]]
# Keep these in sync with the appropriate methods in Style
+@type_check_only
class _ElementCreateImageKwargs(TypedDict, total=False):
border: _Padding
height: float | str
@@ -82,12 +84,15 @@
| tuple[Literal["from"], str] # (fromelement is optional)
)
if sys.platform == "win32" and sys.version_info >= (3, 13):
+ @type_check_only
class _ElementCreateVsapiKwargsPadding(TypedDict, total=False):
padding: _Padding
+ @type_check_only
class _ElementCreateVsapiKwargsMargin(TypedDict, total=False):
padding: _Padding
+ @type_check_only
class _ElementCreateVsapiKwargsSize(TypedDict):
width: float | str
height: float | str
diff --git a/mypy/typeshed/stdlib/unittest/main.pyi b/mypy/typeshed/stdlib/unittest/main.pyi
index 23ead16..e1aeac3 100644
--- a/mypy/typeshed/stdlib/unittest/main.pyi
+++ b/mypy/typeshed/stdlib/unittest/main.pyi
@@ -18,7 +18,7 @@
# not really documented
class TestProgram:
result: unittest.result.TestResult
- module: None | str | ModuleType
+ module: ModuleType | None
verbosity: int
failfast: bool | None
catchbreak: bool | None
@@ -30,7 +30,7 @@
durations: unittest.result._DurationsType | None
def __init__(
self,
- module: None | str | ModuleType = "__main__",
+ module: ModuleType | str | None = "__main__",
defaultTest: str | Iterable[str] | None = None,
argv: list[str] | None = None,
testRunner: type[_TestRunner] | _TestRunner | None = None,