diff --git a/misc/typeshed_patches/0001-Partially-revert-Clean-up-argparse-hacks.patch b/misc/typeshed_patches/0001-Partially-revert-Clean-up-argparse-hacks.patch index 5c31569711e5..a1b1966fea1e 100644 --- a/misc/typeshed_patches/0001-Partially-revert-Clean-up-argparse-hacks.patch +++ b/misc/typeshed_patches/0001-Partially-revert-Clean-up-argparse-hacks.patch @@ -1,4 +1,4 @@ -From 84a9d586544a0408d4654f57f83a93cb048070fb Mon Sep 17 00:00:00 2001 +From b6d495c10e79fb56ff64f8fb90c87894090f9cbe Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Sat, 15 Feb 2025 20:11:06 +0100 Subject: [PATCH] Partially revert Clean up argparse hacks @@ -8,7 +8,7 @@ Subject: [PATCH] Partially revert Clean up argparse hacks 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/mypy/typeshed/stdlib/argparse.pyi b/mypy/typeshed/stdlib/argparse.pyi -index b9fa31139..3c3ba116a 100644 +index ae99eb036..c87b8f4fc 100644 --- a/mypy/typeshed/stdlib/argparse.pyi +++ b/mypy/typeshed/stdlib/argparse.pyi @@ -2,7 +2,7 @@ import sys @@ -41,5 +41,5 @@ index b9fa31139..3c3ba116a 100644 default: Any = ..., type: _ActionType = ..., -- -2.50.1 +2.52.0 diff --git a/misc/typeshed_patches/0001-Remove-use-of-LiteralString-in-builtins-13743.patch b/misc/typeshed_patches/0001-Remove-use-of-LiteralString-in-builtins-13743.patch index f9334251c2bd..b8d0d9812198 100644 --- a/misc/typeshed_patches/0001-Remove-use-of-LiteralString-in-builtins-13743.patch +++ b/misc/typeshed_patches/0001-Remove-use-of-LiteralString-in-builtins-13743.patch @@ -1,4 +1,4 @@ -From 3229a6066cff3d80d6cb923322c2d42a300d0be3 Mon Sep 17 00:00:00 2001 +From ed11d7e0204868ef1a43c17ed950372b1d78f497 Mon Sep 17 00:00:00 2001 From: Shantanu <12621235+hauntsaninja@users.noreply.github.com> Date: Mon, 26 Sep 2022 12:55:07 -0700 Subject: [PATCH] Remove use of LiteralString in builtins (#13743) @@ -8,10 +8,10 @@ Subject: [PATCH] Remove use of LiteralString in builtins (#13743) 1 file changed, 1 insertion(+), 99 deletions(-) diff --git a/mypy/typeshed/stdlib/builtins.pyi b/mypy/typeshed/stdlib/builtins.pyi -index 969d16876..044e264d2 100644 +index 693dd0b77..8acdeadff 100644 --- a/mypy/typeshed/stdlib/builtins.pyi +++ b/mypy/typeshed/stdlib/builtins.pyi -@@ -63,7 +63,6 @@ from typing import ( # noqa: Y022,UP035 +@@ -64,7 +64,6 @@ from typing import ( # noqa: Y022,UP035 from typing_extensions import ( # noqa: Y023 Concatenate, Literal, @@ -19,7 +19,7 @@ index 969d16876..044e264d2 100644 ParamSpec, Self, TypeAlias, -@@ -480,31 +479,16 @@ class str(Sequence[str]): +@@ -482,31 +481,16 @@ class str(Sequence[str]): def __new__(cls, object: object = "") -> Self: ... @overload def __new__(cls, object: ReadableBuffer, encoding: str = "utf-8", errors: str = "strict") -> Self: ... @@ -51,7 +51,7 @@ index 969d16876..044e264d2 100644 def format(self, *args: object, **kwargs: object) -> str: ... def format_map(self, mapping: _FormatMapMapping, /) -> str: ... def index(self, sub: str, start: SupportsIndex | None = None, end: SupportsIndex | None = None, /) -> int: ... -@@ -520,98 +504,34 @@ class str(Sequence[str]): +@@ -522,98 +506,34 @@ class str(Sequence[str]): def isspace(self) -> bool: ... def istitle(self) -> bool: ... def isupper(self) -> bool: ... @@ -150,7 +150,7 @@ index 969d16876..044e264d2 100644 def zfill(self, width: SupportsIndex, /) -> str: ... # type: ignore[misc] @staticmethod @overload -@@ -622,39 +542,21 @@ class str(Sequence[str]): +@@ -624,39 +544,21 @@ class str(Sequence[str]): @staticmethod @overload def maketrans(x: str, y: str, z: str, /) -> dict[int, int | None]: ... @@ -192,5 +192,5 @@ index 969d16876..044e264d2 100644 def __getnewargs__(self) -> tuple[str]: ... def __format__(self, format_spec: str, /) -> str: ... -- -2.51.1 +2.52.0 diff --git a/misc/typeshed_patches/0001-Revert-Remove-redundant-inheritances-from-Iterator.patch b/misc/typeshed_patches/0001-Revert-Remove-redundant-inheritances-from-Iterator.patch index 7110eff5f148..0d64077e63d7 100644 --- a/misc/typeshed_patches/0001-Revert-Remove-redundant-inheritances-from-Iterator.patch +++ b/misc/typeshed_patches/0001-Revert-Remove-redundant-inheritances-from-Iterator.patch @@ -1,4 +1,4 @@ -From 7678bc3f80e4d3f04a0ff0ee3a7d51f49ae4c465 Mon Sep 17 00:00:00 2001 +From 69791281c2c5e919cea9a77c4a771f79d9e70384 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Sat, 21 Dec 2024 22:36:38 +0100 Subject: [PATCH] Revert Remove redundant inheritances from Iterator in @@ -36,10 +36,10 @@ index d663f5d93..f43178e4d 100644 @property def _exception(self) -> BaseException | None: ... diff --git a/mypy/typeshed/stdlib/builtins.pyi b/mypy/typeshed/stdlib/builtins.pyi -index 044e264d2..6d813f172 100644 +index 8acdeadff..5a3bb5908 100644 --- a/mypy/typeshed/stdlib/builtins.pyi +++ b/mypy/typeshed/stdlib/builtins.pyi -@@ -1210,7 +1210,7 @@ class frozenset(AbstractSet[_T_co]): +@@ -1226,7 +1226,7 @@ class frozenset(AbstractSet[_T_co]): def __class_getitem__(cls, item: Any, /) -> GenericAlias: ... @disjoint_base @@ -48,7 +48,7 @@ index 044e264d2..6d813f172 100644 def __new__(cls, iterable: Iterable[_T], start: int = 0) -> Self: ... def __iter__(self) -> Self: ... def __next__(self) -> tuple[int, _T]: ... -@@ -1404,7 +1404,7 @@ else: +@@ -1413,7 +1413,7 @@ else: exit: _sitebuiltins.Quitter @disjoint_base @@ -57,7 +57,7 @@ index 044e264d2..6d813f172 100644 @overload def __new__(cls, function: None, iterable: Iterable[_T | None], /) -> Self: ... @overload -@@ -1468,7 +1468,7 @@ license: _sitebuiltins._Printer +@@ -1477,7 +1477,7 @@ license: _sitebuiltins._Printer def locals() -> dict[str, Any]: ... @disjoint_base @@ -66,7 +66,7 @@ index 044e264d2..6d813f172 100644 # 3.14 adds `strict` argument. if sys.version_info >= (3, 14): @overload -@@ -1775,7 +1775,7 @@ def pow(base: _SupportsSomeKindOfPow, exp: complex, mod: None = None) -> complex +@@ -1784,7 +1784,7 @@ def pow(base: _SupportsSomeKindOfPow, exp: complex, mod: None = None) -> complex quit: _sitebuiltins.Quitter @disjoint_base @@ -75,7 +75,7 @@ index 044e264d2..6d813f172 100644 @overload def __new__(cls, sequence: Reversible[_T], /) -> Iterator[_T]: ... # type: ignore[misc] @overload -@@ -1839,7 +1839,7 @@ def vars(object: type, /) -> types.MappingProxyType[str, Any]: ... +@@ -1848,7 +1848,7 @@ def vars(object: type, /) -> types.MappingProxyType[str, Any]: ... @overload def vars(object: Any = ..., /) -> dict[str, Any]: ... @disjoint_base @@ -107,7 +107,7 @@ index 2c8e7109c..4ed0ab1d8 100644 restkey: _T | None restval: str | Any | None diff --git a/mypy/typeshed/stdlib/fileinput.pyi b/mypy/typeshed/stdlib/fileinput.pyi -index 910d63814..eb942bc55 100644 +index 6778b7648..95164de2f 100644 --- a/mypy/typeshed/stdlib/fileinput.pyi +++ b/mypy/typeshed/stdlib/fileinput.pyi @@ -1,8 +1,8 @@ @@ -118,7 +118,7 @@ index 910d63814..eb942bc55 100644 from types import GenericAlias, TracebackType -from typing import IO, Any, AnyStr, Generic, Literal, Protocol, overload, type_check_only +from typing import IO, Any, AnyStr, Literal, Protocol, overload, type_check_only - from typing_extensions import Self, TypeAlias + from typing_extensions import Self, TypeAlias, deprecated __all__ = [ @@ -105,7 +105,7 @@ def fileno() -> int: ... @@ -131,7 +131,7 @@ index 910d63814..eb942bc55 100644 # encoding and errors are added @overload diff --git a/mypy/typeshed/stdlib/itertools.pyi b/mypy/typeshed/stdlib/itertools.pyi -index fe4ccbdf8..73745fe92 100644 +index 8a924ad8b..5c2bf7f83 100644 --- a/mypy/typeshed/stdlib/itertools.pyi +++ b/mypy/typeshed/stdlib/itertools.pyi @@ -28,7 +28,7 @@ _Predicate: TypeAlias = Callable[[_T], object] @@ -166,7 +166,7 @@ index fe4ccbdf8..73745fe92 100644 -class accumulate(Generic[_T]): +class accumulate(Iterator[_T]): @overload - def __new__(cls, iterable: Iterable[_T], func: None = None, *, initial: _T | None = ...) -> Self: ... + def __new__(cls, iterable: Iterable[_T], func: None = None, *, initial: _T | None = None) -> Self: ... @overload @@ -64,7 +64,7 @@ class accumulate(Generic[_T]): def __next__(self) -> _T: ... @@ -239,7 +239,7 @@ index fe4ccbdf8..73745fe92 100644 +class zip_longest(Iterator[_T_co]): # one iterable (fillvalue doesn't matter) @overload - def __new__(cls, iter1: Iterable[_T1], /, *, fillvalue: object = ...) -> zip_longest[tuple[_T1]]: ... + def __new__(cls, iter1: Iterable[_T1], /, *, fillvalue: object = None) -> zip_longest[tuple[_T1]]: ... @@ -202,7 +202,7 @@ class zip_longest(Generic[_T_co]): def __next__(self) -> _T_co: ... @@ -291,8 +291,8 @@ index fe4ccbdf8..73745fe92 100644 - class batched(Generic[_T_co]): + class batched(Iterator[tuple[_T_co, ...]], Generic[_T_co]): if sys.version_info >= (3, 13): - def __new__(cls, iterable: Iterable[_T_co], n: int, *, strict: bool = False) -> Self: ... - else: + @overload + def __new__(cls, iterable: Iterable[_T], n: Literal[1], *, strict: Literal[True]) -> batched[tuple[_T]]: ... diff --git a/mypy/typeshed/stdlib/multiprocessing/pool.pyi b/mypy/typeshed/stdlib/multiprocessing/pool.pyi index b79f9e773..f276372d0 100644 --- a/mypy/typeshed/stdlib/multiprocessing/pool.pyi @@ -313,10 +313,10 @@ index b79f9e773..f276372d0 100644 def __iter__(self) -> Self: ... def next(self, timeout: float | None = None) -> _T: ... diff --git a/mypy/typeshed/stdlib/sqlite3/__init__.pyi b/mypy/typeshed/stdlib/sqlite3/__init__.pyi -index 6b0f1ba94..882cd143c 100644 +index 04b978b1b..e4604144f 100644 --- a/mypy/typeshed/stdlib/sqlite3/__init__.pyi +++ b/mypy/typeshed/stdlib/sqlite3/__init__.pyi -@@ -407,7 +407,7 @@ class Connection: +@@ -408,7 +408,7 @@ class Connection: ) -> Literal[False]: ... @disjoint_base @@ -326,5 +326,5 @@ index 6b0f1ba94..882cd143c 100644 @property def connection(self) -> Connection: ... -- -2.51.1 +2.52.0 diff --git a/misc/typeshed_patches/0001-Revert-sum-literal-integer-change-13961.patch b/misc/typeshed_patches/0001-Revert-sum-literal-integer-change-13961.patch index 559e32569f2b..d05f66ff2610 100644 --- a/misc/typeshed_patches/0001-Revert-sum-literal-integer-change-13961.patch +++ b/misc/typeshed_patches/0001-Revert-sum-literal-integer-change-13961.patch @@ -1,4 +1,4 @@ -From 16b0b50ec77e470f24145071acde5274a1de53a0 Mon Sep 17 00:00:00 2001 +From 0e30b762e8335f02e19977c055ac7b98e707991c Mon Sep 17 00:00:00 2001 From: Shantanu <12621235+hauntsaninja@users.noreply.github.com> Date: Sat, 29 Oct 2022 12:47:21 -0700 Subject: [PATCH] Revert sum literal integer change (#13961) @@ -19,10 +19,10 @@ within mypy, I might pursue upstreaming this in typeshed. 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mypy/typeshed/stdlib/builtins.pyi b/mypy/typeshed/stdlib/builtins.pyi -index 900c4c93f..d874edd8f 100644 +index 5a3bb5908..0f2196070 100644 --- a/mypy/typeshed/stdlib/builtins.pyi +++ b/mypy/typeshed/stdlib/builtins.pyi -@@ -1782,7 +1782,7 @@ _SupportsSumNoDefaultT = TypeVar("_SupportsSumNoDefaultT", bound=_SupportsSumWit +@@ -1835,7 +1835,7 @@ _SupportsSumNoDefaultT = TypeVar("_SupportsSumNoDefaultT", bound=_SupportsSumWit # without creating many false-positive errors (see #7578). # Instead, we special-case the most common examples of this: bool and literal integers. @overload @@ -32,5 +32,5 @@ index 900c4c93f..d874edd8f 100644 def sum(iterable: Iterable[_SupportsSumNoDefaultT], /) -> _SupportsSumNoDefaultT | Literal[0]: ... @overload -- -2.49.0 +2.52.0 diff --git a/misc/typeshed_patches/0001-Revert-typeshed-ctypes-change.patch b/misc/typeshed_patches/0001-Revert-typeshed-ctypes-change.patch index c16f5ebaa92e..e795be53bce7 100644 --- a/misc/typeshed_patches/0001-Revert-typeshed-ctypes-change.patch +++ b/misc/typeshed_patches/0001-Revert-typeshed-ctypes-change.patch @@ -1,20 +1,20 @@ -From 85c0cfb55c6211c2a47c3f45d2ff28fa76f8204b Mon Sep 17 00:00:00 2001 +From 80a710e0e2c09612c6fc30c644f2052450e69ccd Mon Sep 17 00:00:00 2001 From: AlexWaygood Date: Mon, 1 May 2023 20:34:55 +0100 -Subject: [PATCH] Revert typeshed ctypes change Since the plugin provides - superior type checking: - https://github.com/python/mypy/pull/13987#issuecomment-1310863427 A manual - cherry-pick of e437cdf. +Subject: [PATCH] Revert typeshed ctypes change +The plugin provides superior type checking: +https://github.com/python/mypy/pull/13987#issuecomment-1310863427 +A manual cherry-pick of e437cdf. --- mypy/typeshed/stdlib/_ctypes.pyi | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/mypy/typeshed/stdlib/_ctypes.pyi b/mypy/typeshed/stdlib/_ctypes.pyi -index 944685646..dc8c7b2ca 100644 +index be7792818..b7a3fb104 100644 --- a/mypy/typeshed/stdlib/_ctypes.pyi +++ b/mypy/typeshed/stdlib/_ctypes.pyi -@@ -289,11 +289,7 @@ class Array(_CData, Generic[_CT], metaclass=_PyCArrayType): +@@ -320,11 +320,7 @@ class Array(_CData, Generic[_CT], metaclass=_PyCArrayType): def _type_(self) -> type[_CT]: ... @_type_.setter def _type_(self, value: type[_CT]) -> None: ... @@ -28,5 +28,5 @@ index 944685646..dc8c7b2ca 100644 # TODO: These methods cannot be annotated correctly at the moment. # All of these "Any"s stand for the array's element type, but it's not possible to use _CT -- -2.49.0 +2.52.0 diff --git a/mypy/typeshed/stdlib/_frozen_importlib_external.pyi b/mypy/typeshed/stdlib/_frozen_importlib_external.pyi index 4778be3af1f3..660cee6e84ec 100644 --- a/mypy/typeshed/stdlib/_frozen_importlib_external.pyi +++ b/mypy/typeshed/stdlib/_frozen_importlib_external.pyi @@ -9,7 +9,7 @@ from _typeshed.importlib import LoaderProtocol from collections.abc import Callable, Iterable, Iterator, Mapping, MutableSequence, Sequence from importlib.machinery import ModuleSpec from importlib.metadata import DistributionFinder, PathDistribution -from typing import Any, Final, Literal +from typing import Any, Final, Literal, overload from typing_extensions import Self, deprecated if sys.version_info >= (3, 10): @@ -26,7 +26,13 @@ else: MAGIC_NUMBER: Final[bytes] -def cache_from_source(path: StrPath, debug_override: bool | None = None, *, optimization: Any | None = None) -> str: ... +@overload +@deprecated( + "The `debug_override` parameter is deprecated since Python 3.5; will be removed in Python 3.15. Use `optimization` instead." +) +def cache_from_source(path: StrPath, debug_override: bool, *, optimization: None = None) -> str: ... +@overload +def cache_from_source(path: StrPath, debug_override: None = None, *, optimization: Any | None = None) -> str: ... def source_from_cache(path: StrPath) -> str: ... def decode_source(source_bytes: ReadableBuffer) -> str: ... def spec_from_file_location( diff --git a/mypy/typeshed/stdlib/_tkinter.pyi b/mypy/typeshed/stdlib/_tkinter.pyi index a3868f467c6c..5e46668e08b1 100644 --- a/mypy/typeshed/stdlib/_tkinter.pyi +++ b/mypy/typeshed/stdlib/_tkinter.pyi @@ -1,6 +1,7 @@ import sys +from _typeshed import FileDescriptorLike, Incomplete from collections.abc import Callable -from typing import Any, ClassVar, Final, final +from typing import Any, ClassVar, Final, Literal, final, overload from typing_extensions import TypeAlias, deprecated # _tkinter is meant to be only used internally by tkinter, but some tkinter @@ -54,22 +55,23 @@ _TkinterTraceFunc: TypeAlias = Callable[[tuple[str, ...]], object] @final class TkappType: # Please keep in sync with tkinter.Tk - def adderrorinfo(self, msg: str, /): ... + def adderrorinfo(self, msg: str, /) -> None: ... def call(self, command: Any, /, *args: Any) -> Any: ... - def createcommand(self, name: str, func, /): ... + # TODO: Figure out what arguments the following `func` callbacks should accept + def createcommand(self, name: str, func: Callable[..., object], /) -> None: ... if sys.platform != "win32": - def createfilehandler(self, file, mask: int, func, /): ... - def deletefilehandler(self, file, /) -> None: ... + def createfilehandler(self, file: FileDescriptorLike, mask: int, func: Callable[..., object], /) -> None: ... + def deletefilehandler(self, file: FileDescriptorLike, /) -> None: ... - def createtimerhandler(self, milliseconds: int, func, /): ... - def deletecommand(self, name: str, /): ... - def dooneevent(self, flags: int = 0, /): ... + def createtimerhandler(self, milliseconds: int, func: Callable[..., object], /): ... + def deletecommand(self, name: str, /) -> None: ... + def dooneevent(self, flags: int = 0, /) -> int: ... def eval(self, script: str, /) -> str: ... - def evalfile(self, fileName: str, /): ... - def exprboolean(self, s: str, /): ... - def exprdouble(self, s: str, /): ... - def exprlong(self, s: str, /): ... - def exprstring(self, s: str, /): ... + def evalfile(self, fileName: str, /) -> str: ... + def exprboolean(self, s: str, /) -> Literal[0, 1]: ... + def exprdouble(self, s: str, /) -> float: ... + def exprlong(self, s: str, /) -> int: ... + def exprstring(self, s: str, /) -> str: ... def getboolean(self, arg, /) -> bool: ... def getdouble(self, arg, /) -> float: ... def getint(self, arg, /) -> int: ... @@ -81,15 +83,23 @@ class TkappType: def loadtk(self) -> None: ... def mainloop(self, threshold: int = 0, /) -> None: ... def quit(self) -> None: ... - def record(self, script: str, /): ... + def record(self, script: str, /) -> str: ... def setvar(self, *ags, **kwargs): ... if sys.version_info < (3, 11): @deprecated("Deprecated since Python 3.9; removed in Python 3.11. Use `splitlist()` instead.") def split(self, arg, /): ... - def splitlist(self, arg, /): ... + def splitlist(self, arg, /) -> tuple[Incomplete, ...]: ... def unsetvar(self, *args, **kwargs): ... - def wantobjects(self, *args, **kwargs): ... + if sys.version_info >= (3, 14): + @overload + def wantobjects(self) -> Literal[0, 1]: ... + else: + @overload + def wantobjects(self) -> bool: ... + + @overload + def wantobjects(self, wantobjects: Literal[0, 1] | bool, /) -> None: ... def willdispatch(self) -> None: ... if sys.version_info >= (3, 12): def gettrace(self, /) -> _TkinterTraceFunc | None: ... @@ -112,7 +122,7 @@ TK_VERSION: Final[str] @final class TkttType: - def deletetimerhandler(self): ... + def deletetimerhandler(self) -> None: ... if sys.version_info >= (3, 13): def create( @@ -125,7 +135,7 @@ if sys.version_info >= (3, 13): sync: bool = False, use: str | None = None, /, - ): ... + ) -> TkappType: ... else: def create( @@ -138,7 +148,7 @@ else: sync: bool = False, use: str | None = None, /, - ): ... + ) -> TkappType: ... def getbusywaitinterval() -> int: ... def setbusywaitinterval(new_val: int, /) -> None: ... diff --git a/mypy/typeshed/stdlib/asyncio/base_events.pyi b/mypy/typeshed/stdlib/asyncio/base_events.pyi index 1f493210d665..0d8ac2d47491 100644 --- a/mypy/typeshed/stdlib/asyncio/base_events.pyi +++ b/mypy/typeshed/stdlib/asyncio/base_events.pyi @@ -83,7 +83,16 @@ class BaseEventLoop(AbstractEventLoop): # Future methods def create_future(self) -> Future[Any]: ... # Tasks methods - if sys.version_info >= (3, 11): + if sys.version_info >= (3, 14): + def create_task( + self, + coro: _CoroutineLike[_T], + *, + name: object = None, + context: Context | None = None, + eager_start: bool | None = None, + ) -> Task[_T]: ... + elif sys.version_info >= (3, 11): def create_task(self, coro: _CoroutineLike[_T], *, name: object = None, context: Context | None = None) -> Task[_T]: ... else: def create_task(self, coro: _CoroutineLike[_T], *, name: object = None) -> Task[_T]: ... diff --git a/mypy/typeshed/stdlib/asyncio/events.pyi b/mypy/typeshed/stdlib/asyncio/events.pyi index 5dc698bc5e15..4f2f45355f5b 100644 --- a/mypy/typeshed/stdlib/asyncio/events.pyi +++ b/mypy/typeshed/stdlib/asyncio/events.pyi @@ -161,7 +161,17 @@ class AbstractEventLoop: @abstractmethod def create_future(self) -> Future[Any]: ... # Tasks methods - if sys.version_info >= (3, 11): + if sys.version_info >= (3, 14): + @abstractmethod + def create_task( + self, + coro: _CoroutineLike[_T], + *, + name: str | None = None, + context: Context | None = None, + eager_start: bool | None = None, + ) -> Task[_T]: ... + elif sys.version_info >= (3, 11): @abstractmethod def create_task( self, coro: _CoroutineLike[_T], *, name: str | None = None, context: Context | None = None diff --git a/mypy/typeshed/stdlib/asyncio/taskgroups.pyi b/mypy/typeshed/stdlib/asyncio/taskgroups.pyi index 30b7c9129f6f..2968b0719761 100644 --- a/mypy/typeshed/stdlib/asyncio/taskgroups.pyi +++ b/mypy/typeshed/stdlib/asyncio/taskgroups.pyi @@ -22,5 +22,18 @@ class TaskGroup: async def __aenter__(self) -> Self: ... async def __aexit__(self, et: type[BaseException] | None, exc: BaseException | None, tb: TracebackType | None) -> None: ... - def create_task(self, coro: _CoroutineLike[_T], *, name: str | None = None, context: Context | None = None) -> Task[_T]: ... + if sys.version_info >= (3, 14): + def create_task( + self, + coro: _CoroutineLike[_T], + *, + name: str | None = None, + context: Context | None = None, + eager_start: bool | None = None, + ) -> Task[_T]: ... + else: + def create_task( + self, coro: _CoroutineLike[_T], *, name: str | None = None, context: Context | None = None + ) -> Task[_T]: ... + def _on_task_done(self, task: Task[object]) -> None: ... diff --git a/mypy/typeshed/stdlib/asyncio/tasks.pyi b/mypy/typeshed/stdlib/asyncio/tasks.pyi index 1442f7400a9c..be9b60cd36ae 100644 --- a/mypy/typeshed/stdlib/asyncio/tasks.pyi +++ b/mypy/typeshed/stdlib/asyncio/tasks.pyi @@ -413,7 +413,12 @@ else: def all_tasks(loop: AbstractEventLoop | None = None) -> set[Task[Any]]: ... -if sys.version_info >= (3, 11): +if sys.version_info >= (3, 14): + def create_task( + coro: _CoroutineLike[_T], *, name: str | None = None, context: Context | None = None, eager_start: bool | None = None + ) -> Task[_T]: ... + +elif sys.version_info >= (3, 11): def create_task(coro: _CoroutineLike[_T], *, name: str | None = None, context: Context | None = None) -> Task[_T]: ... else: diff --git a/mypy/typeshed/stdlib/builtins.pyi b/mypy/typeshed/stdlib/builtins.pyi index bd425ff3c212..0f2196070de2 100644 --- a/mypy/typeshed/stdlib/builtins.pyi +++ b/mypy/typeshed/stdlib/builtins.pyi @@ -1078,9 +1078,9 @@ class dict(MutableMapping[_KT, _VT]): # __init__ should be kept roughly in line with `collections.UserDict.__init__`, which has similar semantics # Also multiprocessing.managers.SyncManager.dict() @overload - def __init__(self) -> None: ... + def __init__(self, /) -> None: ... @overload - def __init__(self: dict[str, _VT], **kwargs: _VT) -> None: ... # pyright: ignore[reportInvalidTypeVarUse] #11780 + def __init__(self: dict[str, _VT], /, **kwargs: _VT) -> None: ... # pyright: ignore[reportInvalidTypeVarUse] #11780 @overload def __init__(self, map: SupportsKeysAndGetItem[_KT, _VT], /) -> None: ... @overload @@ -1105,7 +1105,7 @@ class dict(MutableMapping[_KT, _VT]): def __init__(self: dict[str, str], iterable: Iterable[list[str]], /) -> None: ... @overload def __init__(self: dict[bytes, bytes], iterable: Iterable[list[bytes]], /) -> None: ... - def __new__(cls, *args: Any, **kwargs: Any) -> Self: ... + def __new__(cls, /, *args: Any, **kwargs: Any) -> Self: ... def copy(self) -> dict[_KT, _VT]: ... def keys(self) -> dict_keys[_KT, _VT]: ... def values(self) -> dict_values[_KT, _VT]: ... @@ -1184,7 +1184,7 @@ class set(MutableSet[_T]): def __iand__(self, value: AbstractSet[object], /) -> Self: ... def __or__(self, value: AbstractSet[_S], /) -> set[_T | _S]: ... def __ior__(self, value: AbstractSet[_T], /) -> Self: ... # type: ignore[override,misc] - def __sub__(self, value: AbstractSet[_T | None], /) -> set[_T]: ... + def __sub__(self, value: AbstractSet[object], /) -> set[_T]: ... def __isub__(self, value: AbstractSet[object], /) -> Self: ... def __xor__(self, value: AbstractSet[_S], /) -> set[_T | _S]: ... def __ixor__(self, value: AbstractSet[_T], /) -> Self: ... # type: ignore[override,misc] @@ -1215,7 +1215,7 @@ class frozenset(AbstractSet[_T_co]): def __iter__(self) -> Iterator[_T_co]: ... def __and__(self, value: AbstractSet[_T_co], /) -> frozenset[_T_co]: ... def __or__(self, value: AbstractSet[_S], /) -> frozenset[_T_co | _S]: ... - def __sub__(self, value: AbstractSet[_T_co], /) -> frozenset[_T_co]: ... + def __sub__(self, value: AbstractSet[object], /) -> frozenset[_T_co]: ... def __xor__(self, value: AbstractSet[_S], /) -> frozenset[_T_co | _S]: ... def __le__(self, value: AbstractSet[object], /) -> bool: ... def __lt__(self, value: AbstractSet[object], /) -> bool: ... diff --git a/mypy/typeshed/stdlib/cmath.pyi b/mypy/typeshed/stdlib/cmath.pyi index aed4c63862fe..fdf8ae7bfed8 100644 --- a/mypy/typeshed/stdlib/cmath.pyi +++ b/mypy/typeshed/stdlib/cmath.pyi @@ -9,6 +9,7 @@ nan: Final[float] nanj: Final[complex] tau: Final[float] +_F: TypeAlias = SupportsFloat | SupportsIndex _C: TypeAlias = SupportsFloat | SupportsComplex | SupportsIndex | complex def acos(z: _C, /) -> complex: ... @@ -27,7 +28,7 @@ def log(z: _C, base: _C = ..., /) -> complex: ... def log10(z: _C, /) -> complex: ... def phase(z: _C, /) -> float: ... def polar(z: _C, /) -> tuple[float, float]: ... -def rect(r: float, phi: float, /) -> complex: ... +def rect(r: _F, phi: _F, /) -> complex: ... def sin(z: _C, /) -> complex: ... def sinh(z: _C, /) -> complex: ... def sqrt(z: _C, /) -> complex: ... diff --git a/mypy/typeshed/stdlib/ctypes/__init__.pyi b/mypy/typeshed/stdlib/ctypes/__init__.pyi index be2e7449ef31..8d048aa97e7d 100644 --- a/mypy/typeshed/stdlib/ctypes/__init__.pyi +++ b/mypy/typeshed/stdlib/ctypes/__init__.pyi @@ -169,11 +169,12 @@ def create_unicode_buffer(init: int | str, size: int | None = None) -> Array[c_w if sys.version_info >= (3, 13): @deprecated("Deprecated since Python 3.13; will be removed in Python 3.15.") def SetPointerType(pointer: type[_Pointer[Any]], cls: _CTypeBaseType) -> None: ... + @deprecated("Soft deprecated since Python 3.13. Use multiplication instead.") + def ARRAY(typ: _CT, len: int) -> Array[_CT]: ... else: def SetPointerType(pointer: type[_Pointer[Any]], cls: _CTypeBaseType) -> None: ... - -def ARRAY(typ: _CT, len: int) -> Array[_CT]: ... # Soft Deprecated, no plans to remove + def ARRAY(typ: _CT, len: int) -> Array[_CT]: ... if sys.platform == "win32": def DllCanUnloadNow() -> int: ... diff --git a/mypy/typeshed/stdlib/dis.pyi b/mypy/typeshed/stdlib/dis.pyi index 896b50fa9384..52794a588ca8 100644 --- a/mypy/typeshed/stdlib/dis.pyi +++ b/mypy/typeshed/stdlib/dis.pyi @@ -2,8 +2,8 @@ import sys import types from collections.abc import Callable, Iterator from opcode import * # `dis` re-exports it as a part of public API -from typing import IO, Any, Final, NamedTuple -from typing_extensions import Self, TypeAlias, disjoint_base +from typing import IO, Any, Final, NamedTuple, overload +from typing_extensions import Self, TypeAlias, deprecated, disjoint_base __all__ = [ "code_info", @@ -277,7 +277,14 @@ else: def distb(tb: types.TracebackType | None = None, *, file: IO[str] | None = None) -> None: ... if sys.version_info >= (3, 13): - # 3.13 made `show_cache` `None` by default + # 3.13 made `show_caches` `None` by default and has no effect + @overload + def get_instructions(x: _HaveCodeType, *, first_line: int | None = None, adaptive: bool = False) -> Iterator[Instruction]: ... + @overload + @deprecated( + "The `show_caches` parameter is deprecated since Python 3.13. " + "The iterator generates the `Instruction` instances with the `cache_info` field populated." + ) def get_instructions( x: _HaveCodeType, *, first_line: int | None = None, show_caches: bool | None = None, adaptive: bool = False ) -> Iterator[Instruction]: ... diff --git a/mypy/typeshed/stdlib/email/utils.pyi b/mypy/typeshed/stdlib/email/utils.pyi index efc32a7abce2..cece2f2a1119 100644 --- a/mypy/typeshed/stdlib/email/utils.pyi +++ b/mypy/typeshed/stdlib/email/utils.pyi @@ -44,16 +44,7 @@ def parsedate(data: str) -> tuple[int, int, int, int, int, int, int, int, int] | def parsedate_tz(data: None) -> None: ... @overload def parsedate_tz(data: str) -> _PDTZ | None: ... - -if sys.version_info >= (3, 10): - @overload - def parsedate_to_datetime(data: None) -> None: ... - @overload - def parsedate_to_datetime(data: str) -> datetime.datetime: ... - -else: - def parsedate_to_datetime(data: str) -> datetime.datetime: ... - +def parsedate_to_datetime(data: str) -> datetime.datetime: ... def mktime_tz(data: _PDTZ) -> int: ... def formatdate(timeval: float | None = None, localtime: bool = False, usegmt: bool = False) -> str: ... def format_datetime(dt: datetime.datetime, usegmt: bool = False) -> str: ... diff --git a/mypy/typeshed/stdlib/faulthandler.pyi b/mypy/typeshed/stdlib/faulthandler.pyi index 33d08995eb75..17d4eef69af7 100644 --- a/mypy/typeshed/stdlib/faulthandler.pyi +++ b/mypy/typeshed/stdlib/faulthandler.pyi @@ -3,21 +3,23 @@ from _typeshed import FileDescriptorLike def cancel_dump_traceback_later() -> None: ... def disable() -> None: ... -def dump_traceback(file: FileDescriptorLike = ..., all_threads: bool = ...) -> None: ... +def dump_traceback(file: FileDescriptorLike = sys.stderr, all_threads: bool = True) -> None: ... if sys.version_info >= (3, 14): - def dump_c_stack(file: FileDescriptorLike = ...) -> None: ... + def dump_c_stack(file: FileDescriptorLike = sys.stderr) -> None: ... -def dump_traceback_later(timeout: float, repeat: bool = ..., file: FileDescriptorLike = ..., exit: bool = ...) -> None: ... +def dump_traceback_later( + timeout: float, repeat: bool = False, file: FileDescriptorLike = sys.stderr, exit: bool = False +) -> None: ... if sys.version_info >= (3, 14): - def enable(file: FileDescriptorLike = ..., all_threads: bool = ..., c_stack: bool = True) -> None: ... + def enable(file: FileDescriptorLike = sys.stderr, all_threads: bool = True, c_stack: bool = True) -> None: ... else: - def enable(file: FileDescriptorLike = ..., all_threads: bool = ...) -> None: ... + def enable(file: FileDescriptorLike = sys.stderr, all_threads: bool = True) -> None: ... def is_enabled() -> bool: ... if sys.platform != "win32": - def register(signum: int, file: FileDescriptorLike = ..., all_threads: bool = ..., chain: bool = ...) -> None: ... + def register(signum: int, file: FileDescriptorLike = sys.stderr, all_threads: bool = True, chain: bool = False) -> None: ... def unregister(signum: int, /) -> None: ... diff --git a/mypy/typeshed/stdlib/fileinput.pyi b/mypy/typeshed/stdlib/fileinput.pyi index eb942bc55177..95164de2f010 100644 --- a/mypy/typeshed/stdlib/fileinput.pyi +++ b/mypy/typeshed/stdlib/fileinput.pyi @@ -3,7 +3,7 @@ from _typeshed import AnyStr_co, StrOrBytesPath from collections.abc import Callable, Iterable, Iterator from types import GenericAlias, TracebackType from typing import IO, Any, AnyStr, Literal, Protocol, overload, type_check_only -from typing_extensions import Self, TypeAlias +from typing_extensions import Self, TypeAlias, deprecated __all__ = [ "input", @@ -207,4 +207,9 @@ if sys.version_info >= (3, 10): else: def hook_compressed(filename: StrOrBytesPath, mode: str) -> IO[Any]: ... -def hook_encoded(encoding: str, errors: str | None = None) -> Callable[[StrOrBytesPath, str], IO[Any]]: ... +if sys.version_info >= (3, 10): + @deprecated("Deprecated since Python 3.10. Use `fileinput.input` or `fileinput.FileInput` instead.") + def hook_encoded(encoding: str, errors: str | None = None) -> Callable[[StrOrBytesPath, str], IO[Any]]: ... + +else: + def hook_encoded(encoding: str, errors: str | None = None) -> Callable[[StrOrBytesPath, str], IO[Any]]: ... diff --git a/mypy/typeshed/stdlib/ftplib.pyi b/mypy/typeshed/stdlib/ftplib.pyi index 44bc2165fe0e..73eaa8a34e57 100644 --- a/mypy/typeshed/stdlib/ftplib.pyi +++ b/mypy/typeshed/stdlib/ftplib.pyi @@ -1,11 +1,11 @@ import sys -from _typeshed import SupportsRead, SupportsReadline +from _typeshed import StrOrBytesPath, SupportsRead, SupportsReadline from collections.abc import Callable, Iterable, Iterator from socket import socket from ssl import SSLContext from types import TracebackType -from typing import Any, Final, Literal, TextIO -from typing_extensions import Self +from typing import Any, Final, Literal, TextIO, overload +from typing_extensions import Self, deprecated __all__ = ["FTP", "error_reply", "error_temp", "error_perm", "error_proto", "all_errors", "FTP_TLS"] @@ -120,23 +120,43 @@ class FTP_TLS(FTP): encoding: str = "utf-8", ) -> None: ... else: + @overload def __init__( self, host: str = "", user: str = "", passwd: str = "", acct: str = "", - keyfile: str | None = None, - certfile: str | None = None, + keyfile: None = None, + certfile: None = None, context: SSLContext | None = None, timeout: float | None = ..., source_address: tuple[str, int] | None = None, *, encoding: str = "utf-8", ) -> None: ... - ssl_version: int - keyfile: str | None - certfile: str | None + @overload + @deprecated( + "The `keyfile`, `certfile` parameters are deprecated since Python 3.6; " + "removed in Python 3.12. Use `context` parameter instead." + ) + def __init__( + self, + host: str = "", + user: str = "", + passwd: str = "", + acct: str = "", + keyfile: StrOrBytesPath | None = None, + certfile: StrOrBytesPath | None = None, + context: None = None, + timeout: float | None = ..., + source_address: tuple[str, int] | None = None, + *, + encoding: str = "utf-8", + ) -> None: ... + ssl_version: int + keyfile: StrOrBytesPath | None + certfile: StrOrBytesPath | None context: SSLContext def login(self, user: str = "", passwd: str = "", acct: str = "", secure: bool = True) -> str: ... def auth(self) -> str: ... diff --git a/mypy/typeshed/stdlib/functools.pyi b/mypy/typeshed/stdlib/functools.pyi index 47baf917294d..52d0d0958134 100644 --- a/mypy/typeshed/stdlib/functools.pyi +++ b/mypy/typeshed/stdlib/functools.pyi @@ -54,14 +54,14 @@ class _CacheParameters(TypedDict): typed: bool @final -class _lru_cache_wrapper(Generic[_T]): - __wrapped__: Callable[..., _T] - def __call__(self, *args: Hashable, **kwargs: Hashable) -> _T: ... +class _lru_cache_wrapper(Generic[_T_co]): + __wrapped__: Callable[..., _T_co] + def __call__(self, *args: Hashable, **kwargs: Hashable) -> _T_co: ... def cache_info(self) -> _CacheInfo: ... def cache_clear(self) -> None: ... def cache_parameters(self) -> _CacheParameters: ... - def __copy__(self) -> _lru_cache_wrapper[_T]: ... - def __deepcopy__(self, memo: Any, /) -> _lru_cache_wrapper[_T]: ... + def __copy__(self) -> _lru_cache_wrapper[_T_co]: ... + def __deepcopy__(self, memo: Any, /) -> _lru_cache_wrapper[_T_co]: ... @overload def lru_cache(maxsize: int | None = 128, typed: bool = False) -> Callable[[Callable[..., _T]], _lru_cache_wrapper[_T]]: ... diff --git a/mypy/typeshed/stdlib/gc.pyi b/mypy/typeshed/stdlib/gc.pyi index 06fb6b47c2d1..ec1ed2681c5c 100644 --- a/mypy/typeshed/stdlib/gc.pyi +++ b/mypy/typeshed/stdlib/gc.pyi @@ -30,4 +30,4 @@ def is_tracked(obj: Any, /) -> bool: ... def is_finalized(obj: Any, /) -> bool: ... def isenabled() -> bool: ... def set_debug(flags: int, /) -> None: ... -def set_threshold(threshold0: int, threshold1: int = ..., threshold2: int = ..., /) -> None: ... +def set_threshold(threshold0: int, threshold1: int = 0, threshold2: int = 0, /) -> None: ... diff --git a/mypy/typeshed/stdlib/hashlib.pyi b/mypy/typeshed/stdlib/hashlib.pyi index 924136301b21..1763c2318273 100644 --- a/mypy/typeshed/stdlib/hashlib.pyi +++ b/mypy/typeshed/stdlib/hashlib.pyi @@ -66,7 +66,7 @@ else: "pbkdf2_hmac", ) -def new(name: str, data: ReadableBuffer = b"", *, usedforsecurity: bool = ...) -> HASH: ... +def new(name: str, data: ReadableBuffer = b"", *, usedforsecurity: bool = True) -> HASH: ... algorithms_guaranteed: AbstractSet[str] algorithms_available: AbstractSet[str] diff --git a/mypy/typeshed/stdlib/http/client.pyi b/mypy/typeshed/stdlib/http/client.pyi index 1568567d5854..699ef0e4c6d6 100644 --- a/mypy/typeshed/stdlib/http/client.pyi +++ b/mypy/typeshed/stdlib/http/client.pyi @@ -3,12 +3,12 @@ import io import ssl import sys import types -from _typeshed import MaybeNone, ReadableBuffer, SupportsRead, SupportsReadline, WriteableBuffer +from _typeshed import MaybeNone, ReadableBuffer, StrOrBytesPath, SupportsRead, SupportsReadline, WriteableBuffer from collections.abc import Callable, Iterable, Iterator, Mapping from email._policybase import _MessageT from socket import socket from typing import BinaryIO, Final, TypeVar, overload -from typing_extensions import Self, TypeAlias +from typing_extensions import Self, TypeAlias, deprecated __all__ = [ "HTTPResponse", @@ -160,8 +160,11 @@ class HTTPResponse(io.BufferedIOBase, BinaryIO): # type: ignore[misc] # incomp def __exit__( self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: types.TracebackType | None ) -> None: ... - def info(self) -> email.message.Message: ... + @deprecated("Deprecated since Python 3.9. Use `HTTPResponse.headers` attribute instead.") + def info(self) -> HTTPMessage: ... + @deprecated("Deprecated since Python 3.9. Use `HTTPResponse.url` attribute instead.") def geturl(self) -> str: ... + @deprecated("Deprecated since Python 3.9. Use `HTTPResponse.status` attribute instead.") def getcode(self) -> int: ... def begin(self) -> None: ... @@ -220,12 +223,31 @@ class HTTPSConnection(HTTPConnection): blocksize: int = 8192, ) -> None: ... else: + @overload def __init__( self, host: str, port: int | None = None, - key_file: str | None = None, - cert_file: str | None = None, + key_file: None = None, + cert_file: None = None, + timeout: float | None = ..., + source_address: tuple[str, int] | None = None, + *, + context: ssl.SSLContext | None = None, + check_hostname: None = None, + blocksize: int = 8192, + ) -> None: ... + @overload + @deprecated( + "The `key_file`, `cert_file`, `check_hostname` parameters are deprecated since Python 3.6; " + "removed in Python 3.12. Use `context` parameter instead." + ) + def __init__( + self, + host: str, + port: int | None = None, + key_file: StrOrBytesPath | None = None, + cert_file: StrOrBytesPath | None = None, timeout: float | None = ..., source_address: tuple[str, int] | None = None, *, @@ -233,6 +255,8 @@ class HTTPSConnection(HTTPConnection): check_hostname: bool | None = None, blocksize: int = 8192, ) -> None: ... + key_file: StrOrBytesPath | None + cert_file: StrOrBytesPath | None class HTTPException(Exception): ... diff --git a/mypy/typeshed/stdlib/http/cookies.pyi b/mypy/typeshed/stdlib/http/cookies.pyi index 4df12e3125d4..0373eae8ab29 100644 --- a/mypy/typeshed/stdlib/http/cookies.pyi +++ b/mypy/typeshed/stdlib/http/cookies.pyi @@ -1,3 +1,4 @@ +from _typeshed import MaybeNone from collections.abc import Iterable, Mapping from types import GenericAlias from typing import Any, Generic, TypeVar, overload @@ -21,11 +22,11 @@ class CookieError(Exception): ... class Morsel(dict[str, Any], Generic[_T]): @property - def value(self) -> str: ... + def value(self) -> str | MaybeNone: ... @property - def coded_value(self) -> _T: ... + def coded_value(self) -> _T | MaybeNone: ... @property - def key(self) -> str: ... + def key(self) -> str | MaybeNone: ... def __init__(self) -> None: ... def set(self, key: str, val: str, coded_val: _T) -> None: ... def setdefault(self, key: str, val: str | None = None) -> str: ... diff --git a/mypy/typeshed/stdlib/imaplib.pyi b/mypy/typeshed/stdlib/imaplib.pyi index 1f0e0106006b..94b96f0a1283 100644 --- a/mypy/typeshed/stdlib/imaplib.pyi +++ b/mypy/typeshed/stdlib/imaplib.pyi @@ -1,7 +1,7 @@ import subprocess import sys import time -from _typeshed import ReadableBuffer, SizedBuffer, Unused +from _typeshed import ReadableBuffer, SizedBuffer, StrOrBytesPath, Unused from builtins import list as _list # conflicts with a method named "list" from collections.abc import Callable, Generator from datetime import datetime @@ -9,7 +9,7 @@ from re import Pattern from socket import socket as _socket from ssl import SSLContext, SSLSocket from types import TracebackType -from typing import IO, Any, Literal, SupportsAbs, SupportsInt +from typing import IO, Any, Literal, SupportsAbs, SupportsInt, overload from typing_extensions import Self, TypeAlias, deprecated __all__ = ["IMAP4", "IMAP4_stream", "Internaldate2tuple", "Int2AP", "ParseFlags", "Time2Internaldate", "IMAP4_SSL"] @@ -61,7 +61,9 @@ class IMAP4: def socket(self) -> _socket: ... def recent(self) -> _CommandResults: ... def response(self, code: str) -> _CommandResults: ... - def append(self, mailbox: str, flags: str, date_time: str, message: ReadableBuffer) -> tuple[str, _list[bytes]]: ... + def append( + self, mailbox: str | None, flags: str | None, date_time: _TimeLike | None, message: ReadableBuffer + ) -> tuple[str, _list[bytes]]: ... def authenticate(self, mechanism: str, authobject: Callable[[bytes], bytes | None]) -> tuple[str, str]: ... def capability(self) -> _CommandResults: ... def check(self) -> _CommandResults: ... @@ -120,23 +122,37 @@ if sys.version_info >= (3, 14): def burst(self, interval: float = 0.1) -> Generator[tuple[str, float | None]]: ... class IMAP4_SSL(IMAP4): - if sys.version_info < (3, 12): - keyfile: str - certfile: str if sys.version_info >= (3, 12): def __init__( self, host: str = "", port: int = 993, *, ssl_context: SSLContext | None = None, timeout: float | None = None ) -> None: ... else: + @overload def __init__( self, host: str = "", port: int = 993, - keyfile: str | None = None, - certfile: str | None = None, + keyfile: None = None, + certfile: None = None, ssl_context: SSLContext | None = None, timeout: float | None = None, ) -> None: ... + @overload + @deprecated( + "The `keyfile`, `certfile` parameters are deprecated since Python 3.6; " + "removed in Python 3.12. Use `ssl_context` parameter instead." + ) + def __init__( + self, + host: str = "", + port: int = 993, + keyfile: StrOrBytesPath | None = None, + certfile: StrOrBytesPath | None = None, + ssl_context: None = None, + timeout: float | None = None, + ) -> None: ... + keyfile: StrOrBytesPath | None + certfile: StrOrBytesPath | None sslobj: SSLSocket if sys.version_info >= (3, 14): @property @@ -172,4 +188,7 @@ class _Authenticator: def Internaldate2tuple(resp: ReadableBuffer) -> time.struct_time | None: ... def Int2AP(num: SupportsAbs[SupportsInt]) -> bytes: ... def ParseFlags(resp: ReadableBuffer) -> tuple[bytes, ...]: ... -def Time2Internaldate(date_time: float | time.struct_time | time._TimeTuple | datetime | str) -> str: ... + +_TimeLike: TypeAlias = float | time.struct_time | time._TimeTuple | datetime | str + +def Time2Internaldate(date_time: _TimeLike) -> str: ... diff --git a/mypy/typeshed/stdlib/importlib/resources/abc.pyi b/mypy/typeshed/stdlib/importlib/resources/abc.pyi index 9be594a7dc2f..477339ea7429 100644 --- a/mypy/typeshed/stdlib/importlib/resources/abc.pyi +++ b/mypy/typeshed/stdlib/importlib/resources/abc.pyi @@ -4,8 +4,10 @@ from abc import ABCMeta, abstractmethod from collections.abc import Iterator from io import BufferedReader from typing import IO, Any, Literal, Protocol, overload, runtime_checkable +from typing_extensions import deprecated if sys.version_info >= (3, 11): + @deprecated("Deprecated since Python 3.12. Use `importlib.resources.abc.TraversableResources` instead.") class ResourceReader(metaclass=ABCMeta): @abstractmethod def open_resource(self, resource: str) -> IO[bytes]: ... diff --git a/mypy/typeshed/stdlib/inspect.pyi b/mypy/typeshed/stdlib/inspect.pyi index 55ae61617af7..c48d63bc4f32 100644 --- a/mypy/typeshed/stdlib/inspect.pyi +++ b/mypy/typeshed/stdlib/inspect.pyi @@ -547,6 +547,7 @@ def formatargvalues( formatvalue: Callable[[Any], str] | None = ..., ) -> str: ... def getmro(cls: type) -> tuple[type, ...]: ... +@deprecated("Deprecated since Python 3.5. Use `Signature.bind` and `Signature.bind_partial` instead.") def getcallargs(func: Callable[_P, Any], /, *args: _P.args, **kwds: _P.kwargs) -> dict[str, Any]: ... class ClosureVars(NamedTuple): diff --git a/mypy/typeshed/stdlib/itertools.pyi b/mypy/typeshed/stdlib/itertools.pyi index 73745fe92d9e..5c2bf7f83bba 100644 --- a/mypy/typeshed/stdlib/itertools.pyi +++ b/mypy/typeshed/stdlib/itertools.pyi @@ -32,7 +32,7 @@ class count(Iterator[_N]): @overload def __new__(cls) -> count[int]: ... @overload - def __new__(cls, start: _N, step: _Step = ...) -> count[_N]: ... + def __new__(cls, start: _N, step: _Step = 1) -> count[_N]: ... @overload def __new__(cls, *, step: _N) -> count[_N]: ... def __next__(self) -> _N: ... @@ -57,9 +57,9 @@ class repeat(Iterator[_T]): @disjoint_base class accumulate(Iterator[_T]): @overload - def __new__(cls, iterable: Iterable[_T], func: None = None, *, initial: _T | None = ...) -> Self: ... + def __new__(cls, iterable: Iterable[_T], func: None = None, *, initial: _T | None = None) -> Self: ... @overload - def __new__(cls, iterable: Iterable[_S], func: Callable[[_T, _S], _T], *, initial: _T | None = ...) -> Self: ... + def __new__(cls, iterable: Iterable[_S], func: Callable[[_T, _S], _T], *, initial: _T | None = None) -> Self: ... def __iter__(self) -> Self: ... def __next__(self) -> _T: ... @@ -105,7 +105,7 @@ class islice(Iterator[_T]): @overload def __new__(cls, iterable: Iterable[_T], stop: int | None, /) -> Self: ... @overload - def __new__(cls, iterable: Iterable[_T], start: int | None, stop: int | None, step: int | None = ..., /) -> Self: ... + def __new__(cls, iterable: Iterable[_T], start: int | None, stop: int | None, step: int | None = 1, /) -> Self: ... def __iter__(self) -> Self: ... def __next__(self) -> _T: ... @@ -126,7 +126,7 @@ def tee(iterable: Iterable[_T], n: int = 2, /) -> tuple[Iterator[_T], ...]: ... class zip_longest(Iterator[_T_co]): # one iterable (fillvalue doesn't matter) @overload - def __new__(cls, iter1: Iterable[_T1], /, *, fillvalue: object = ...) -> zip_longest[tuple[_T1]]: ... + def __new__(cls, iter1: Iterable[_T1], /, *, fillvalue: object = None) -> zip_longest[tuple[_T1]]: ... # two iterables @overload # In the overloads without fillvalue, all of the tuple members could theoretically be None, @@ -298,7 +298,7 @@ class permutations(Iterator[_T_co]): @overload def __new__(cls, iterable: Iterable[_T], r: Literal[5]) -> permutations[tuple[_T, _T, _T, _T, _T]]: ... @overload - def __new__(cls, iterable: Iterable[_T], r: int | None = ...) -> permutations[tuple[_T, ...]]: ... + def __new__(cls, iterable: Iterable[_T], r: int | None = None) -> permutations[tuple[_T, ...]]: ... def __iter__(self) -> Self: ... def __next__(self) -> _T_co: ... @@ -343,9 +343,24 @@ if sys.version_info >= (3, 12): @disjoint_base class batched(Iterator[tuple[_T_co, ...]], Generic[_T_co]): if sys.version_info >= (3, 13): - def __new__(cls, iterable: Iterable[_T_co], n: int, *, strict: bool = False) -> Self: ... + @overload + def __new__(cls, iterable: Iterable[_T], n: Literal[1], *, strict: Literal[True]) -> batched[tuple[_T]]: ... + @overload + def __new__(cls, iterable: Iterable[_T], n: Literal[2], *, strict: Literal[True]) -> batched[tuple[_T, _T]]: ... + @overload + def __new__(cls, iterable: Iterable[_T], n: Literal[3], *, strict: Literal[True]) -> batched[tuple[_T, _T, _T]]: ... + @overload + def __new__( + cls, iterable: Iterable[_T], n: Literal[4], *, strict: Literal[True] + ) -> batched[tuple[_T, _T, _T, _T]]: ... + @overload + def __new__( + cls, iterable: Iterable[_T], n: Literal[5], *, strict: Literal[True] + ) -> batched[tuple[_T, _T, _T, _T, _T]]: ... + @overload + def __new__(cls, iterable: Iterable[_T], n: int, *, strict: bool = False) -> batched[tuple[_T, ...]]: ... else: - def __new__(cls, iterable: Iterable[_T_co], n: int) -> Self: ... + def __new__(cls, iterable: Iterable[_T], n: int) -> batched[tuple[_T, ...]]: ... def __iter__(self) -> Self: ... - def __next__(self) -> tuple[_T_co, ...]: ... + def __next__(self) -> _T_co: ... diff --git a/mypy/typeshed/stdlib/multiprocessing/reduction.pyi b/mypy/typeshed/stdlib/multiprocessing/reduction.pyi index 490ae195c20e..ddc676efccc3 100644 --- a/mypy/typeshed/stdlib/multiprocessing/reduction.pyi +++ b/mypy/typeshed/stdlib/multiprocessing/reduction.pyi @@ -1,6 +1,6 @@ import pickle import sys -from _pickle import _ReducedType +from _pickle import _BufferCallback, _ReducedType from _typeshed import HasFileno, SupportsWrite, Unused from abc import ABCMeta from builtins import type as Type # alias to avoid name clash @@ -19,7 +19,14 @@ HAVE_SEND_HANDLE: Final[bool] class ForkingPickler(pickle.Pickler): dispatch_table: _DispatchTableType - def __init__(self, file: SupportsWrite[bytes], protocol: int | None = ...) -> None: ... + def __init__( + self, + file: SupportsWrite[bytes], + protocol: int | None = None, + fix_imports: bool = True, + buffer_callback: _BufferCallback = None, + /, + ) -> None: ... @classmethod def register(cls, type: Type, reduce: Callable[[Any], _ReducedType]) -> None: ... @classmethod diff --git a/mypy/typeshed/stdlib/os/__init__.pyi b/mypy/typeshed/stdlib/os/__init__.pyi index 7801b91702ab..9e02fbf9e106 100644 --- a/mypy/typeshed/stdlib/os/__init__.pyi +++ b/mypy/typeshed/stdlib/os/__init__.pyi @@ -1037,10 +1037,10 @@ def fdopen( mode: OpenTextMode = "r", buffering: int = -1, encoding: str | None = None, - errors: str | None = ..., - newline: str | None = ..., - closefd: bool = ..., - opener: _Opener | None = ..., + errors: str | None = None, + newline: str | None = None, + closefd: bool = True, + opener: _Opener | None = None, ) -> TextIOWrapper: ... @overload def fdopen( @@ -1050,8 +1050,8 @@ def fdopen( encoding: None = None, errors: None = None, newline: None = None, - closefd: bool = ..., - opener: _Opener | None = ..., + closefd: bool = True, + opener: _Opener | None = None, ) -> FileIO: ... @overload def fdopen( @@ -1061,8 +1061,8 @@ def fdopen( encoding: None = None, errors: None = None, newline: None = None, - closefd: bool = ..., - opener: _Opener | None = ..., + closefd: bool = True, + opener: _Opener | None = None, ) -> BufferedRandom: ... @overload def fdopen( @@ -1072,8 +1072,8 @@ def fdopen( encoding: None = None, errors: None = None, newline: None = None, - closefd: bool = ..., - opener: _Opener | None = ..., + closefd: bool = True, + opener: _Opener | None = None, ) -> BufferedWriter: ... @overload def fdopen( @@ -1083,8 +1083,8 @@ def fdopen( encoding: None = None, errors: None = None, newline: None = None, - closefd: bool = ..., - opener: _Opener | None = ..., + closefd: bool = True, + opener: _Opener | None = None, ) -> BufferedReader: ... @overload def fdopen( @@ -1094,8 +1094,8 @@ def fdopen( encoding: None = None, errors: None = None, newline: None = None, - closefd: bool = ..., - opener: _Opener | None = ..., + closefd: bool = True, + opener: _Opener | None = None, ) -> BinaryIO: ... @overload def fdopen( @@ -1103,10 +1103,10 @@ def fdopen( mode: str, buffering: int = -1, encoding: str | None = None, - errors: str | None = ..., - newline: str | None = ..., - closefd: bool = ..., - opener: _Opener | None = ..., + errors: str | None = None, + newline: str | None = None, + closefd: bool = True, + opener: _Opener | None = None, ) -> IO[Any]: ... def close(fd: int) -> None: ... def closerange(fd_low: int, fd_high: int, /) -> None: ... @@ -1538,13 +1538,13 @@ else: env: _ExecEnv | None, # None allowed starting in 3.13 /, *, - file_actions: Sequence[tuple[Any, ...]] | None = ..., - setpgroup: int | None = ..., - resetids: bool = ..., - setsid: bool = ..., - setsigmask: Iterable[int] = ..., - setsigdef: Iterable[int] = ..., - scheduler: tuple[Any, sched_param] | None = ..., + file_actions: Sequence[tuple[Any, ...]] | None = (), + setpgroup: int = ..., + resetids: bool = False, + setsid: bool = False, + setsigmask: Iterable[int] = (), + setsigdef: Iterable[int] = (), + scheduler: tuple[Any, sched_param] = ..., ) -> int: ... def posix_spawnp( path: StrOrBytesPath, @@ -1552,13 +1552,13 @@ else: env: _ExecEnv | None, # None allowed starting in 3.13 /, *, - file_actions: Sequence[tuple[Any, ...]] | None = ..., - setpgroup: int | None = ..., - resetids: bool = ..., - setsid: bool = ..., - setsigmask: Iterable[int] = ..., - setsigdef: Iterable[int] = ..., - scheduler: tuple[Any, sched_param] | None = ..., + file_actions: Sequence[tuple[Any, ...]] | None = (), + setpgroup: int = ..., + resetids: bool = False, + setsid: bool = False, + setsigmask: Iterable[int] = (), + setsigdef: Iterable[int] = (), + scheduler: tuple[Any, sched_param] = ..., ) -> int: ... else: def posix_spawn( @@ -1567,13 +1567,13 @@ else: env: _ExecEnv, /, *, - file_actions: Sequence[tuple[Any, ...]] | None = ..., - setpgroup: int | None = ..., - resetids: bool = ..., - setsid: bool = ..., - setsigmask: Iterable[int] = ..., - setsigdef: Iterable[int] = ..., - scheduler: tuple[Any, sched_param] | None = ..., + file_actions: Sequence[tuple[Any, ...]] | None = (), + setpgroup: int = ..., + resetids: bool = False, + setsid: bool = False, + setsigmask: Iterable[int] = (), + setsigdef: Iterable[int] = (), + scheduler: tuple[Any, sched_param] = ..., ) -> int: ... def posix_spawnp( path: StrOrBytesPath, @@ -1581,13 +1581,13 @@ else: env: _ExecEnv, /, *, - file_actions: Sequence[tuple[Any, ...]] | None = ..., - setpgroup: int | None = ..., - resetids: bool = ..., - setsid: bool = ..., - setsigmask: Iterable[int] = ..., - setsigdef: Iterable[int] = ..., - scheduler: tuple[Any, sched_param] | None = ..., + file_actions: Sequence[tuple[Any, ...]] | None = (), + setpgroup: int = ..., + resetids: bool = False, + setsid: bool = False, + setsigmask: Iterable[int] = (), + setsigdef: Iterable[int] = (), + scheduler: tuple[Any, sched_param] = ..., ) -> int: ... POSIX_SPAWN_OPEN: Final = 0 @@ -1674,12 +1674,12 @@ if sys.platform == "linux": MFD_HUGE_2GB: Final[int] MFD_HUGE_16GB: Final[int] def memfd_create(name: str, flags: int = ...) -> int: ... - def copy_file_range(src: int, dst: int, count: int, offset_src: int | None = ..., offset_dst: int | None = ...) -> int: ... + def copy_file_range(src: int, dst: int, count: int, offset_src: int | None = None, offset_dst: int | None = None) -> int: ... def waitstatus_to_exitcode(status: int) -> int: ... if sys.platform == "linux": - def pidfd_open(pid: int, flags: int = ...) -> int: ... + def pidfd_open(pid: int, flags: int = 0) -> int: ... if sys.version_info >= (3, 12) and sys.platform == "linux": PIDFD_NONBLOCK: Final = 2048 @@ -1703,8 +1703,8 @@ if sys.version_info >= (3, 10) and sys.platform == "linux": src: FileDescriptor, dst: FileDescriptor, count: int, - offset_src: int | None = ..., - offset_dst: int | None = ..., + offset_src: int | None = None, + offset_dst: int | None = None, flags: int = 0, ) -> int: ... diff --git a/mypy/typeshed/stdlib/pathlib/__init__.pyi b/mypy/typeshed/stdlib/pathlib/__init__.pyi index 33652d922568..26dde2accd8d 100644 --- a/mypy/typeshed/stdlib/pathlib/__init__.pyi +++ b/mypy/typeshed/stdlib/pathlib/__init__.pyi @@ -104,6 +104,10 @@ class PurePath(PathLike[str]): if sys.version_info >= (3, 14): def is_relative_to(self, other: StrPath) -> bool: ... elif sys.version_info >= (3, 12): + @overload + def is_relative_to(self, other: StrPath, /) -> bool: ... + @overload + @deprecated("Passing additional arguments is deprecated since Python 3.12; removed in Python 3.14.") def is_relative_to(self, other: StrPath, /, *_deprecated: StrPath) -> bool: ... else: def is_relative_to(self, *other: StrPath) -> bool: ... @@ -116,6 +120,10 @@ class PurePath(PathLike[str]): if sys.version_info >= (3, 14): def relative_to(self, other: StrPath, *, walk_up: bool = False) -> Self: ... elif sys.version_info >= (3, 12): + @overload + def relative_to(self, other: StrPath, /, *, walk_up: bool = False) -> Self: ... + @overload + @deprecated("Passing additional arguments is deprecated since Python 3.12; removed in Python 3.14.") def relative_to(self, other: StrPath, /, *_deprecated: StrPath, walk_up: bool = False) -> Self: ... else: def relative_to(self, *other: StrPath) -> Self: ... diff --git a/mypy/typeshed/stdlib/poplib.pyi b/mypy/typeshed/stdlib/poplib.pyi index 9ff2b764aeb6..f5669ec87e87 100644 --- a/mypy/typeshed/stdlib/poplib.pyi +++ b/mypy/typeshed/stdlib/poplib.pyi @@ -1,10 +1,11 @@ import socket import ssl import sys +from _typeshed import StrOrBytesPath from builtins import list as _list # conflicts with a method named "list" from re import Pattern from typing import Any, BinaryIO, Final, NoReturn, overload -from typing_extensions import TypeAlias +from typing_extensions import TypeAlias, deprecated __all__ = ["POP3", "error_proto", "POP3_SSL"] @@ -58,15 +59,32 @@ class POP3_SSL(POP3): ) -> None: ... def stls(self, context: Any = None) -> NoReturn: ... else: + @overload def __init__( self, host: str, port: int = 995, - keyfile: str | None = None, - certfile: str | None = None, + keyfile: None = None, + certfile: None = None, timeout: float = ..., context: ssl.SSLContext | None = None, ) -> None: ... + @overload + @deprecated( + "The `keyfile`, `certfile` parameters are deprecated since Python 3.6; " + "removed in Python 3.12. Use `context` parameter instead." + ) + def __init__( + self, + host: str, + port: int = 995, + keyfile: StrOrBytesPath | None = None, + certfile: StrOrBytesPath | None = None, + timeout: float = ..., + context: None = None, + ) -> None: ... + keyfile: StrOrBytesPath | None + certfile: StrOrBytesPath | None # "context" is actually the last argument, # but that breaks LSP and it doesn't really matter because all the arguments are ignored def stls(self, context: Any = None, keyfile: Any = None, certfile: Any = None) -> NoReturn: ... diff --git a/mypy/typeshed/stdlib/pstats.pyi b/mypy/typeshed/stdlib/pstats.pyi index c4dee1f6b8f6..c1da2aea0fc5 100644 --- a/mypy/typeshed/stdlib/pstats.pyi +++ b/mypy/typeshed/stdlib/pstats.pyi @@ -61,7 +61,7 @@ class Stats: sort_arg_dict_default: _SortArgDict def __init__( self, - arg: None | str | Profile | _cProfile = ..., + arg: None | str | Profile | _cProfile = None, /, *args: None | str | Profile | _cProfile | Self, stream: IO[Any] | None = None, diff --git a/mypy/typeshed/stdlib/pydoc.pyi b/mypy/typeshed/stdlib/pydoc.pyi index 935f9420f88c..f8129ac20ade 100644 --- a/mypy/typeshed/stdlib/pydoc.pyi +++ b/mypy/typeshed/stdlib/pydoc.pyi @@ -5,7 +5,7 @@ from builtins import list as _list # "list" conflicts with method name from collections.abc import Callable, Container, Mapping, MutableMapping from reprlib import Repr from types import MethodType, ModuleType, TracebackType -from typing import IO, Any, AnyStr, Final, NoReturn, Protocol, TypeVar, type_check_only +from typing import IO, Any, AnyStr, Final, NoReturn, Protocol, TypeVar, overload, type_check_only from typing_extensions import TypeGuard, deprecated __all__ = ["help"] @@ -48,7 +48,14 @@ class ErrorDuringImport(Exception): exc: type[BaseException] | None value: BaseException | None tb: TracebackType | None - def __init__(self, filename: str, exc_info: OptExcInfo) -> None: ... + if sys.version_info >= (3, 12): + @overload + def __init__(self, filename: str, exc_info: BaseException) -> None: ... + @overload + @deprecated("A tuple value for `exc_info` parameter is deprecated since Python 3.12. Use an exception instance.") + def __init__(self, filename: str, exc_info: OptExcInfo) -> None: ... + else: + def __init__(self, filename: str, exc_info: OptExcInfo) -> None: ... def importfile(path: str) -> ModuleType: ... def safeimport(path: str, forceload: bool = ..., cache: MutableMapping[str, ModuleType] = {}) -> ModuleType | None: ... diff --git a/mypy/typeshed/stdlib/random.pyi b/mypy/typeshed/stdlib/random.pyi index a797794b8050..08619bf66351 100644 --- a/mypy/typeshed/stdlib/random.pyi +++ b/mypy/typeshed/stdlib/random.pyi @@ -3,8 +3,8 @@ import sys from _typeshed import SupportsLenAndGetItem from collections.abc import Callable, Iterable, MutableSequence, Sequence, Set as AbstractSet from fractions import Fraction -from typing import Any, ClassVar, NoReturn, TypeVar -from typing_extensions import Self +from typing import Any, ClassVar, NoReturn, TypeVar, overload +from typing_extensions import Self, deprecated __all__ = [ "Random", @@ -67,6 +67,10 @@ class Random(_random.Random): if sys.version_info >= (3, 11): def shuffle(self, x: MutableSequence[Any]) -> None: ... else: + @overload + def shuffle(self, x: MutableSequence[Any]) -> None: ... + @overload + @deprecated("The `random` parameter is deprecated since Python 3.9; removed in Python 3.11.") def shuffle(self, x: MutableSequence[Any], random: Callable[[], float] | None = None) -> None: ... if sys.version_info >= (3, 11): def sample(self, population: Sequence[_T], k: int, *, counts: Iterable[int] | None = None) -> list[_T]: ... diff --git a/mypy/typeshed/stdlib/sched.pyi b/mypy/typeshed/stdlib/sched.pyi index 52f87ab68ff5..436d9984ee4d 100644 --- a/mypy/typeshed/stdlib/sched.pyi +++ b/mypy/typeshed/stdlib/sched.pyi @@ -1,4 +1,5 @@ import sys +import time from collections.abc import Callable from typing import Any, ClassVar, NamedTuple, type_check_only from typing_extensions import TypeAlias @@ -32,7 +33,9 @@ class scheduler: timefunc: Callable[[], float] delayfunc: Callable[[float], object] - def __init__(self, timefunc: Callable[[], float] = ..., delayfunc: Callable[[float], object] = ...) -> None: ... + def __init__( + self, timefunc: Callable[[], float] = time.monotonic, delayfunc: Callable[[float], object] = time.sleep + ) -> None: ... def enterabs( self, time: float, priority: Any, action: _ActionCallback, argument: tuple[Any, ...] = (), kwargs: dict[str, Any] = ... ) -> Event: ... diff --git a/mypy/typeshed/stdlib/secrets.pyi b/mypy/typeshed/stdlib/secrets.pyi index 4861b6f09340..76479af97a07 100644 --- a/mypy/typeshed/stdlib/secrets.pyi +++ b/mypy/typeshed/stdlib/secrets.pyi @@ -1,12 +1,14 @@ from _typeshed import SupportsLenAndGetItem from hmac import compare_digest as compare_digest from random import SystemRandom as SystemRandom -from typing import TypeVar +from typing import Final, TypeVar __all__ = ["choice", "randbelow", "randbits", "SystemRandom", "token_bytes", "token_hex", "token_urlsafe", "compare_digest"] _T = TypeVar("_T") +DEFAULT_ENTROPY: Final[int] + def randbelow(exclusive_upper_bound: int) -> int: ... def randbits(k: int) -> int: ... def choice(seq: SupportsLenAndGetItem[_T]) -> _T: ... diff --git a/mypy/typeshed/stdlib/select.pyi b/mypy/typeshed/stdlib/select.pyi index 43a9e4274b23..d2b1d6d676e5 100644 --- a/mypy/typeshed/stdlib/select.pyi +++ b/mypy/typeshed/stdlib/select.pyi @@ -2,8 +2,8 @@ import sys from _typeshed import FileDescriptorLike from collections.abc import Iterable from types import TracebackType -from typing import Any, ClassVar, Final, TypeVar, final -from typing_extensions import Never, Self +from typing import Any, ClassVar, Final, TypeVar, final, overload +from typing_extensions import Never, Self, deprecated if sys.platform != "win32": PIPE_BUF: Final[int] @@ -52,13 +52,7 @@ if sys.platform != "linux" and sys.platform != "win32": ident: int udata: Any def __init__( - self, - ident: FileDescriptorLike, - filter: int = ..., - flags: int = ..., - fflags: int = ..., - data: Any = ..., - udata: Any = ..., + self, ident: FileDescriptorLike, filter: int = ..., flags: int = ..., fflags: int = 0, data: Any = 0, udata: Any = 0 ) -> None: ... __hash__: ClassVar[None] # type: ignore[assignment] @@ -118,12 +112,19 @@ if sys.platform != "linux" and sys.platform != "win32": if sys.platform == "linux": @final class epoll: - def __new__(self, sizehint: int = ..., flags: int = ...) -> Self: ... + @overload + def __new__(self, sizehint: int = -1) -> Self: ... + @overload + @deprecated( + "The `flags` parameter is deprecated since Python 3.4. " + "Use `os.set_inheritable()` to make the file descriptor inheritable." + ) + def __new__(self, sizehint: int = -1, flags: int = 0) -> Self: ... def __enter__(self) -> Self: ... def __exit__( self, exc_type: type[BaseException] | None = None, - exc_value: BaseException | None = ..., + exc_value: BaseException | None = None, exc_tb: TracebackType | None = None, /, ) -> None: ... @@ -164,4 +165,4 @@ if sys.platform != "linux" and sys.platform != "darwin" and sys.platform != "win def register(self, fd: FileDescriptorLike, eventmask: int = ...) -> None: ... def modify(self, fd: FileDescriptorLike, eventmask: int = ...) -> None: ... def unregister(self, fd: FileDescriptorLike) -> None: ... - def poll(self, timeout: float | None = ...) -> list[tuple[int, int]]: ... + def poll(self, timeout: float | None = None) -> list[tuple[int, int]]: ... diff --git a/mypy/typeshed/stdlib/smtplib.pyi b/mypy/typeshed/stdlib/smtplib.pyi index 6a8467689367..74b5ea2cb6fc 100644 --- a/mypy/typeshed/stdlib/smtplib.pyi +++ b/mypy/typeshed/stdlib/smtplib.pyi @@ -1,6 +1,6 @@ import sys from _socket import _Address as _SourceAddress -from _typeshed import ReadableBuffer, SizedBuffer +from _typeshed import ReadableBuffer, SizedBuffer, StrOrBytesPath from collections.abc import Sequence from email.message import Message as _Message from re import Pattern @@ -8,7 +8,7 @@ from socket import socket from ssl import SSLContext from types import TracebackType from typing import Any, Final, Protocol, overload, type_check_only -from typing_extensions import Self, TypeAlias +from typing_extensions import Self, TypeAlias, deprecated __all__ = [ "SMTPException", @@ -131,8 +131,15 @@ class SMTP: if sys.version_info >= (3, 12): def starttls(self, *, context: SSLContext | None = None) -> _Reply: ... else: + @overload + def starttls(self, keyfile: None = None, certfile: None = None, context: SSLContext | None = None) -> _Reply: ... + @overload + @deprecated( + "The `keyfile`, `certfile` parameters are deprecated since Python 3.6; " + "removed in Python 3.12. Use `context` parameter instead." + ) def starttls( - self, keyfile: str | None = None, certfile: str | None = None, context: SSLContext | None = None + self, keyfile: StrOrBytesPath | None = None, certfile: StrOrBytesPath | None = None, context: None = None ) -> _Reply: ... def sendmail( @@ -155,8 +162,6 @@ class SMTP: def quit(self) -> _Reply: ... class SMTP_SSL(SMTP): - keyfile: str | None - certfile: str | None context: SSLContext if sys.version_info >= (3, 12): def __init__( @@ -170,17 +175,36 @@ class SMTP_SSL(SMTP): context: SSLContext | None = None, ) -> None: ... else: + @overload def __init__( self, host: str = "", port: int = 0, local_hostname: str | None = None, - keyfile: str | None = None, - certfile: str | None = None, + keyfile: None = None, + certfile: None = None, timeout: float = ..., source_address: _SourceAddress | None = None, context: SSLContext | None = None, ) -> None: ... + @overload + @deprecated( + "The `keyfile`, `certfile` parameters are deprecated since Python 3.6; " + "removed in Python 3.12. Use `context` parameter instead." + ) + def __init__( + self, + host: str = "", + port: int = 0, + local_hostname: str | None = None, + keyfile: StrOrBytesPath | None = None, + certfile: StrOrBytesPath | None = None, + timeout: float = ..., + source_address: _SourceAddress | None = None, + context: None = None, + ) -> None: ... + keyfile: StrOrBytesPath | None + certfile: StrOrBytesPath | None LMTP_PORT: Final = 2003 diff --git a/mypy/typeshed/stdlib/socket.pyi b/mypy/typeshed/stdlib/socket.pyi index 92bf48c3a2d8..24923192d1a4 100644 --- a/mypy/typeshed/stdlib/socket.pyi +++ b/mypy/typeshed/stdlib/socket.pyi @@ -1409,7 +1409,7 @@ if sys.platform == "win32": else: def socketpair( - family: int | AddressFamily | None = None, type: SocketType | int = ..., proto: int = 0 + family: int | AddressFamily | None = None, type: SocketKind | int = ..., proto: int = 0 ) -> tuple[socket, socket]: ... class SocketIO(RawIOBase): diff --git a/mypy/typeshed/stdlib/sre_compile.pyi b/mypy/typeshed/stdlib/sre_compile.pyi index d8f0b7937e99..486b2f743eeb 100644 --- a/mypy/typeshed/stdlib/sre_compile.pyi +++ b/mypy/typeshed/stdlib/sre_compile.pyi @@ -3,9 +3,10 @@ from sre_constants import * from sre_constants import _NamedIntConstant from sre_parse import SubPattern from typing import Any, Final +from typing_extensions import TypeIs MAXCODE: Final[int] def dis(code: list[_NamedIntConstant]) -> None: ... -def isstring(obj: Any) -> bool: ... +def isstring(obj: object) -> TypeIs[str | bytes]: ... def compile(p: str | bytes | SubPattern, flags: int = 0) -> Pattern[Any]: ... diff --git a/mypy/typeshed/stdlib/ssl.pyi b/mypy/typeshed/stdlib/ssl.pyi index aa94fc84255e..2053005f1ba6 100644 --- a/mypy/typeshed/stdlib/ssl.pyi +++ b/mypy/typeshed/stdlib/ssl.pyi @@ -83,36 +83,6 @@ class SSLCertVerificationError(SSLError, ValueError): CertificateError = SSLCertVerificationError -if sys.version_info < (3, 12): - @deprecated("Deprecated since Python 3.7; removed in Python 3.12. Use `SSLContext.wrap_socket()` instead.") - def wrap_socket( - sock: socket.socket, - keyfile: StrOrBytesPath | None = None, - certfile: StrOrBytesPath | None = None, - server_side: bool = False, - cert_reqs: int = ..., - ssl_version: int = ..., - ca_certs: str | None = None, - do_handshake_on_connect: bool = True, - suppress_ragged_eofs: bool = True, - ciphers: str | None = None, - ) -> SSLSocket: ... - @deprecated("Deprecated since Python 3.7; removed in Python 3.12.") - def match_hostname(cert: _PeerCertRetDictType, hostname: str) -> None: ... - -def cert_time_to_seconds(cert_time: str) -> int: ... - -if sys.version_info >= (3, 10): - def get_server_certificate( - addr: tuple[str, int], ssl_version: int = ..., ca_certs: str | None = None, timeout: float = ... - ) -> str: ... - -else: - def get_server_certificate(addr: tuple[str, int], ssl_version: int = ..., ca_certs: str | None = None) -> str: ... - -def DER_cert_to_PEM_cert(der_cert_bytes: ReadableBuffer) -> str: ... -def PEM_cert_to_DER_cert(pem_cert_string: str) -> bytes: ... - class DefaultVerifyPaths(NamedTuple): cafile: str capath: str @@ -321,7 +291,9 @@ class SSLSocket(socket.socket): @overload def sendto(self, data: ReadableBuffer, flags_or_addr: int, addr: socket._Address) -> int: ... def shutdown(self, how: int) -> None: ... + @deprecated("Deprecated since Python 3.6. Use `SSLSocket.recv` method instead.") def read(self, len: int = 1024, buffer: bytearray | None = None) -> bytes: ... + @deprecated("Deprecated since Python 3.6. Use `SSLSocket.send` method instead.") def write(self, data: ReadableBuffer) -> int: ... def do_handshake(self, block: bool = False) -> None: ... # block is undocumented @overload @@ -354,6 +326,40 @@ class SSLSocket(socket.socket): def get_verified_chain(self) -> list[bytes]: ... def get_unverified_chain(self) -> list[bytes]: ... +if sys.version_info < (3, 12): + @deprecated("Deprecated since Python 3.7; removed in Python 3.12. Use `SSLContext.wrap_socket()` instead.") + def wrap_socket( + sock: socket.socket, + keyfile: StrOrBytesPath | None = None, + certfile: StrOrBytesPath | None = None, + server_side: bool = False, + cert_reqs: int = VerifyMode.CERT_NONE, + ssl_version: int = _SSLMethod.PROTOCOL_TLS, + ca_certs: str | None = None, + do_handshake_on_connect: bool = True, + suppress_ragged_eofs: bool = True, + ciphers: str | None = None, + ) -> SSLSocket: ... + @deprecated("Deprecated since Python 3.7; removed in Python 3.12.") + def match_hostname(cert: _PeerCertRetDictType, hostname: str) -> None: ... + +def cert_time_to_seconds(cert_time: str) -> int: ... +def DER_cert_to_PEM_cert(der_cert_bytes: ReadableBuffer) -> str: ... +def PEM_cert_to_DER_cert(pem_cert_string: str) -> bytes: ... + +if sys.version_info >= (3, 10): + def get_server_certificate( + addr: tuple[str, int], + ssl_version: int = _SSLMethod.PROTOCOL_TLS_CLIENT, + ca_certs: str | None = None, + timeout: float = ..., + ) -> str: ... + +else: + def get_server_certificate( + addr: tuple[str, int], ssl_version: int = _SSLMethod.PROTOCOL_TLS_CLIENT, ca_certs: str | None = None + ) -> str: ... + class TLSVersion(enum.IntEnum): MINIMUM_SUPPORTED = -2 MAXIMUM_SUPPORTED = -1 @@ -446,7 +452,7 @@ if sys.version_info >= (3, 10): def _create_unverified_context( protocol: int | None = None, *, - cert_reqs: int = ..., + cert_reqs: int = VerifyMode.CERT_NONE, check_hostname: bool = False, purpose: Purpose = Purpose.SERVER_AUTH, certfile: StrOrBytesPath | None = None, @@ -460,7 +466,7 @@ else: def _create_unverified_context( protocol: int = ..., *, - cert_reqs: int = ..., + cert_reqs: int = VerifyMode.CERT_NONE, check_hostname: bool = False, purpose: Purpose = Purpose.SERVER_AUTH, certfile: StrOrBytesPath | None = None, diff --git a/mypy/typeshed/stdlib/statistics.pyi b/mypy/typeshed/stdlib/statistics.pyi index ba9e5f1b6b71..188bed3375bf 100644 --- a/mypy/typeshed/stdlib/statistics.pyi +++ b/mypy/typeshed/stdlib/statistics.pyi @@ -1,9 +1,9 @@ import sys from _typeshed import SupportsRichComparisonT -from collections.abc import Callable, Hashable, Iterable, Sequence +from collections.abc import Callable, Hashable, Iterable, Sequence, Sized from decimal import Decimal from fractions import Fraction -from typing import Literal, NamedTuple, SupportsFloat, SupportsIndex, TypeVar +from typing import Literal, NamedTuple, Protocol, SupportsFloat, SupportsIndex, TypeVar from typing_extensions import Self, TypeAlias __all__ = [ @@ -41,6 +41,10 @@ _HashableT = TypeVar("_HashableT", bound=Hashable) # Used in NormalDist.samples and kde_random _Seed: TypeAlias = int | float | str | bytes | bytearray # noqa: Y041 +# Used in linear_regression +_T_co = TypeVar("_T_co", covariant=True) + +class _SizedIterable(Iterable[_T_co], Sized, Protocol[_T_co]): ... class StatisticsError(ValueError): ... if sys.version_info >= (3, 11): @@ -129,11 +133,13 @@ if sys.version_info >= (3, 10): if sys.version_info >= (3, 11): def linear_regression( - regressor: Sequence[_Number], dependent_variable: Sequence[_Number], /, *, proportional: bool = False + regressor: _SizedIterable[_Number], dependent_variable: _SizedIterable[_Number], /, *, proportional: bool = False ) -> LinearRegression: ... elif sys.version_info >= (3, 10): - def linear_regression(regressor: Sequence[_Number], dependent_variable: Sequence[_Number], /) -> LinearRegression: ... + def linear_regression( + regressor: _SizedIterable[_Number], dependent_variable: _SizedIterable[_Number], / + ) -> LinearRegression: ... if sys.version_info >= (3, 13): _Kernel: TypeAlias = Literal[ diff --git a/mypy/typeshed/stdlib/sys/_monitoring.pyi b/mypy/typeshed/stdlib/sys/_monitoring.pyi index db799e6f32f8..83f1e7dd0f1d 100644 --- a/mypy/typeshed/stdlib/sys/_monitoring.pyi +++ b/mypy/typeshed/stdlib/sys/_monitoring.pyi @@ -59,10 +59,10 @@ class _events: def get_events(tool_id: int, /) -> int: ... def set_events(tool_id: int, event_set: int, /) -> None: ... def get_local_events(tool_id: int, code: CodeType, /) -> int: ... -def set_local_events(tool_id: int, code: CodeType, event_set: int, /) -> int: ... +def set_local_events(tool_id: int, code: CodeType, event_set: int, /) -> None: ... def restart_events() -> None: ... DISABLE: Final[object] MISSING: Final[object] -def register_callback(tool_id: int, event: int, func: Callable[..., Any] | None, /) -> Callable[..., Any] | None: ... +def register_callback(tool_id: int, event: int, func: Callable[..., object] | None, /) -> Callable[..., Any] | None: ... diff --git a/mypy/typeshed/stdlib/syslog.pyi b/mypy/typeshed/stdlib/syslog.pyi index 1e0d0d383902..b639c28c7f2d 100644 --- a/mypy/typeshed/stdlib/syslog.pyi +++ b/mypy/typeshed/stdlib/syslog.pyi @@ -49,7 +49,7 @@ if sys.platform != "win32": def LOG_MASK(pri: int, /) -> int: ... def LOG_UPTO(pri: int, /) -> int: ... def closelog() -> None: ... - def openlog(ident: str = ..., logoption: int = ..., facility: int = ...) -> None: ... + def openlog(ident: str = ..., logoption: int = 0, facility: int = ...) -> None: ... def setlogmask(maskpri: int, /) -> int: ... @overload def syslog(priority: int, message: str) -> None: ... diff --git a/mypy/typeshed/stdlib/tarfile.pyi b/mypy/typeshed/stdlib/tarfile.pyi index 4ef096be330e..5eecdd350c0a 100644 --- a/mypy/typeshed/stdlib/tarfile.pyi +++ b/mypy/typeshed/stdlib/tarfile.pyi @@ -127,9 +127,9 @@ class TarFile: encoding: str | None errors: str fileobject: type[ExFileObject] # undocumented - pax_headers: Mapping[str, str] | None + pax_headers: Mapping[str, str] debug: int | None - errorlevel: int | None + errorlevel: int offset: int # undocumented extraction_filter: _FilterFunction | None if sys.version_info >= (3, 13): diff --git a/mypy/typeshed/stdlib/timeit.pyi b/mypy/typeshed/stdlib/timeit.pyi index a5da943c8484..61935815f68b 100644 --- a/mypy/typeshed/stdlib/timeit.pyi +++ b/mypy/typeshed/stdlib/timeit.pyi @@ -1,3 +1,4 @@ +import time from collections.abc import Callable, Sequence from typing import IO, Any from typing_extensions import TypeAlias @@ -11,7 +12,11 @@ default_timer: _Timer class Timer: def __init__( - self, stmt: _Stmt = "pass", setup: _Stmt = "pass", timer: _Timer = ..., globals: dict[str, Any] | None = None + self, + stmt: _Stmt = "pass", + setup: _Stmt = "pass", + timer: _Timer = time.perf_counter, + globals: dict[str, Any] | None = None, ) -> None: ... def print_exc(self, file: IO[str] | None = None) -> None: ... def timeit(self, number: int = 1000000) -> float: ... @@ -19,12 +24,16 @@ class Timer: def autorange(self, callback: Callable[[int, float], object] | None = None) -> tuple[int, float]: ... def timeit( - stmt: _Stmt = "pass", setup: _Stmt = "pass", timer: _Timer = ..., number: int = 1000000, globals: dict[str, Any] | None = None + stmt: _Stmt = "pass", + setup: _Stmt = "pass", + timer: _Timer = time.perf_counter, + number: int = 1000000, + globals: dict[str, Any] | None = None, ) -> float: ... def repeat( stmt: _Stmt = "pass", setup: _Stmt = "pass", - timer: _Timer = ..., + timer: _Timer = time.perf_counter, repeat: int = 5, number: int = 1000000, globals: dict[str, Any] | None = None, diff --git a/mypy/typeshed/stdlib/tkinter/__init__.pyi b/mypy/typeshed/stdlib/tkinter/__init__.pyi index ef57faa2b009..90225a8a3652 100644 --- a/mypy/typeshed/stdlib/tkinter/__init__.pyi +++ b/mypy/typeshed/stdlib/tkinter/__init__.pyi @@ -1,6 +1,6 @@ import _tkinter import sys -from _typeshed import Incomplete, MaybeNone, StrOrBytesPath +from _typeshed import FileDescriptorLike, Incomplete, MaybeNone, StrOrBytesPath from collections.abc import Callable, Iterable, Mapping, Sequence from tkinter.constants import * from tkinter.font import _FontDescription @@ -1005,34 +1005,43 @@ class Tk(Misc, Wm): # Tk has __getattr__ so that tk_instance.foo falls back to tk_instance.tk.foo # Please keep in sync with _tkinter.TkappType. # Some methods are intentionally missing because they are inherited from Misc instead. - def adderrorinfo(self, msg: str, /): ... + def adderrorinfo(self, msg: str, /) -> None: ... def call(self, command: Any, /, *args: Any) -> Any: ... - def createcommand(self, name: str, func, /): ... + # TODO: Figure out what arguments the following `func` callbacks should accept + def createcommand(self, name: str, func: Callable[..., object], /) -> None: ... if sys.platform != "win32": - def createfilehandler(self, file, mask: int, func, /): ... - def deletefilehandler(self, file, /) -> None: ... + def createfilehandler(self, file: FileDescriptorLike, mask: int, func: Callable[..., object], /) -> None: ... + def deletefilehandler(self, file: FileDescriptorLike, /) -> None: ... - def createtimerhandler(self, milliseconds: int, func, /): ... - def dooneevent(self, flags: int = 0, /): ... + def createtimerhandler(self, milliseconds: int, func: Callable[..., object], /): ... + def dooneevent(self, flags: int = 0, /) -> int: ... def eval(self, script: str, /) -> str: ... - def evalfile(self, fileName: str, /): ... - def exprboolean(self, s: str, /): ... - def exprdouble(self, s: str, /): ... - def exprlong(self, s: str, /): ... - def exprstring(self, s: str, /): ... + def evalfile(self, fileName: str, /) -> str: ... + def exprboolean(self, s: str, /) -> Literal[0, 1]: ... + def exprdouble(self, s: str, /) -> float: ... + def exprlong(self, s: str, /) -> int: ... + def exprstring(self, s: str, /) -> str: ... def globalgetvar(self, *args, **kwargs): ... def globalsetvar(self, *args, **kwargs): ... def globalunsetvar(self, *args, **kwargs): ... def interpaddr(self) -> int: ... def loadtk(self) -> None: ... - def record(self, script: str, /): ... + def record(self, script: str, /) -> str: ... if sys.version_info < (3, 11): @deprecated("Deprecated since Python 3.9; removed in Python 3.11. Use `splitlist()` instead.") def split(self, arg, /): ... - def splitlist(self, arg, /): ... + def splitlist(self, arg, /) -> tuple[Incomplete, ...]: ... def unsetvar(self, *args, **kwargs): ... - def wantobjects(self, *args, **kwargs): ... + if sys.version_info >= (3, 14): + @overload + def wantobjects(self) -> Literal[0, 1]: ... + else: + @overload + def wantobjects(self) -> bool: ... + + @overload + def wantobjects(self, wantobjects: Literal[0, 1] | bool, /) -> None: ... def willdispatch(self) -> None: ... def Tcl(screenName: str | None = None, baseName: str | None = None, className: str = "Tk", useTk: bool = False) -> Tk: ... diff --git a/mypy/typeshed/stdlib/tkinter/ttk.pyi b/mypy/typeshed/stdlib/tkinter/ttk.pyi index 1d72acd99512..7143c7cce592 100644 --- a/mypy/typeshed/stdlib/tkinter/ttk.pyi +++ b/mypy/typeshed/stdlib/tkinter/ttk.pyi @@ -2,10 +2,10 @@ import _tkinter import sys import tkinter from _typeshed import MaybeNone -from collections.abc import Callable, Iterable +from collections.abc import Callable, Iterable, Sequence from tkinter.font import _FontDescription -from typing import Any, Literal, TypedDict, overload, type_check_only -from typing_extensions import Never, TypeAlias, Unpack +from typing import Any, Literal, TypedDict, TypeVar, overload, type_check_only +from typing_extensions import Never, ParamSpec, TypeAlias, Unpack __all__ = [ "Button", @@ -54,6 +54,9 @@ _Statespec: TypeAlias = tuple[Unpack[tuple[str, ...]], Any] _ImageStatespec: TypeAlias = tuple[Unpack[tuple[str, ...]], tkinter._Image | str] _VsapiStatespec: TypeAlias = tuple[Unpack[tuple[str, ...]], int] +_P = ParamSpec("_P") +_T = TypeVar("_T") + 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 @@ -201,10 +204,15 @@ class Style: def theme_use(self, themename: None = None) -> str: ... class Widget(tkinter.Widget): - def __init__(self, master: tkinter.Misc | None, widgetname, kw=None) -> None: ... + def __init__(self, master: tkinter.Misc | None, widgetname: str | None, kw: dict[str, Any] | None = None) -> None: ... def identify(self, x: int, y: int) -> str: ... - def instate(self, statespec, callback=None, *args, **kw): ... - def state(self, statespec=None): ... + @overload + def instate(self, statespec: Sequence[str], callback: None = None) -> bool: ... + @overload + def instate( + self, statespec: Sequence[str], callback: Callable[_P, _T], *args: _P.args, **kw: _P.kwargs + ) -> Literal[False] | _T: ... + def state(self, statespec: Sequence[str] | None = None) -> tuple[str, ...]: ... class Button(Widget): def __init__( diff --git a/mypy/typeshed/stdlib/types.pyi b/mypy/typeshed/stdlib/types.pyi index 0293e5cb0b4b..568f6ea68d0b 100644 --- a/mypy/typeshed/stdlib/types.pyi +++ b/mypy/typeshed/stdlib/types.pyi @@ -400,7 +400,7 @@ class GeneratorType(Generator[_YieldT_co, _SendT_contra, _ReturnT_co]): @property def gi_code(self) -> CodeType: ... @property - def gi_frame(self) -> FrameType: ... + def gi_frame(self) -> FrameType | None: ... @property def gi_running(self) -> bool: ... @property @@ -429,7 +429,7 @@ class AsyncGeneratorType(AsyncGenerator[_YieldT_co, _SendT_contra]): @property def ag_code(self) -> CodeType: ... @property - def ag_frame(self) -> FrameType: ... + def ag_frame(self) -> FrameType | None: ... @property def ag_running(self) -> bool: ... __name__: str @@ -462,13 +462,8 @@ class CoroutineType(Coroutine[_YieldT_co, _SendT_nd_contra, _ReturnT_nd_co]): def cr_await(self) -> Any | None: ... @property def cr_code(self) -> CodeType: ... - if sys.version_info >= (3, 12): - @property - def cr_frame(self) -> FrameType | None: ... - else: - @property - def cr_frame(self) -> FrameType: ... - + @property + def cr_frame(self) -> FrameType | None: ... @property def cr_running(self) -> bool: ... @property diff --git a/mypy/typeshed/stdlib/typing.pyi b/mypy/typeshed/stdlib/typing.pyi index 8b36ff7b1a92..5521055bdef3 100644 --- a/mypy/typeshed/stdlib/typing.pyi +++ b/mypy/typeshed/stdlib/typing.pyi @@ -952,7 +952,7 @@ if sys.version_info >= (3, 14): localns: Mapping[str, Any] | None = None, include_extras: bool = False, *, - format: Format | None = None, + format: Format | None = None, # Default: Format.VALUE ) -> dict[str, Any]: ... # AnnotationForm else: diff --git a/mypy/typeshed/stdlib/urllib/request.pyi b/mypy/typeshed/stdlib/urllib/request.pyi index a00e7406ee1e..f7e1f278d3e6 100644 --- a/mypy/typeshed/stdlib/urllib/request.pyi +++ b/mypy/typeshed/stdlib/urllib/request.pyi @@ -6,7 +6,7 @@ from email.message import Message from http.client import HTTPConnection, HTTPMessage, HTTPResponse from http.cookiejar import CookieJar from re import Pattern -from typing import IO, Any, ClassVar, NoReturn, Protocol, TypeVar, overload, type_check_only +from typing import IO, Any, ClassVar, Literal, NoReturn, Protocol, TypeVar, overload, type_check_only from typing_extensions import TypeAlias, deprecated from urllib.error import HTTPError as HTTPError from urllib.response import addclosehook, addinfourl @@ -65,16 +65,32 @@ if sys.version_info >= (3, 13): ) -> _UrlopenRet: ... else: + @overload def urlopen( url: str | Request, data: _DataType | None = None, timeout: float | None = ..., *, - cafile: str | None = None, - capath: str | None = None, - cadefault: bool = False, + cafile: None = None, + capath: None = None, + cadefault: Literal[False] = False, context: ssl.SSLContext | None = None, ) -> _UrlopenRet: ... + @overload + @deprecated( + "The `cafile`, `capath`, `cadefault` parameters are deprecated since Python 3.6; " + "removed in Python 3.13. Use `context` parameter instead." + ) + def urlopen( + url: str | Request, + data: _DataType | None = None, + timeout: float | None = ..., + *, + cafile: StrOrBytesPath | None = None, + capath: StrOrBytesPath | None = None, + cadefault: bool = False, + context: None = None, + ) -> _UrlopenRet: ... def install_opener(opener: OpenerDirector) -> None: ... def build_opener(*handlers: BaseHandler | Callable[[], BaseHandler]) -> OpenerDirector: ... diff --git a/mypy/typeshed/stdlib/urllib/response.pyi b/mypy/typeshed/stdlib/urllib/response.pyi index 65df9cdff58f..459b9d1bbdda 100644 --- a/mypy/typeshed/stdlib/urllib/response.pyi +++ b/mypy/typeshed/stdlib/urllib/response.pyi @@ -4,6 +4,7 @@ from collections.abc import Callable, Iterable from email.message import Message from types import TracebackType from typing import IO, Any +from typing_extensions import deprecated __all__ = ["addbase", "addclosehook", "addinfo", "addinfourl"] @@ -32,9 +33,13 @@ class addinfo(addbase): class addinfourl(addinfo): url: str - code: int | None + code: int | None # Deprecated since Python 3.9. Use `addinfourl.status` attribute instead. @property def status(self) -> int | None: ... def __init__(self, fp: IO[bytes], headers: Message, url: str, code: int | None = None) -> None: ... + @deprecated("Deprecated since Python 3.9. Use `addinfourl.url` attribute instead.") def geturl(self) -> str: ... + @deprecated("Deprecated since Python 3.9. Use `addinfourl.headers` attribute instead.") + def info(self) -> Message: ... + @deprecated("Deprecated since Python 3.9. Use `addinfourl.status` attribute instead.") def getcode(self) -> int | None: ... diff --git a/mypy/typeshed/stdlib/xml/etree/ElementTree.pyi b/mypy/typeshed/stdlib/xml/etree/ElementTree.pyi index 18fcaed37625..5c16bcc4ff23 100644 --- a/mypy/typeshed/stdlib/xml/etree/ElementTree.pyi +++ b/mypy/typeshed/stdlib/xml/etree/ElementTree.pyi @@ -258,6 +258,10 @@ class _IterParseIterator(Iterator[tuple[str, Element]], Protocol): if sys.version_info >= (3, 11): def __del__(self) -> None: ... +@overload +def iterparse(source: _FileRead, events: Sequence[str] | None = None) -> _IterParseIterator: ... +@overload +@deprecated("The `parser` parameter is deprecated since Python 3.4.") def iterparse(source: _FileRead, events: Sequence[str] | None = None, parser: XMLParser | None = None) -> _IterParseIterator: ... _EventQueue: TypeAlias = tuple[str] | tuple[str, tuple[str, str]] | tuple[str, None] diff --git a/mypy/typeshed/stdlib/zipfile/__init__.pyi b/mypy/typeshed/stdlib/zipfile/__init__.pyi index df53cdedb4f8..19d8117a621f 100644 --- a/mypy/typeshed/stdlib/zipfile/__init__.pyi +++ b/mypy/typeshed/stdlib/zipfile/__init__.pyi @@ -363,8 +363,8 @@ else: encoding: str | None = None, errors: str | None = None, newline: str | None = None, - line_buffering: bool = ..., - write_through: bool = ..., + line_buffering: bool = False, + write_through: bool = False, *, pwd: bytes | None = None, ) -> TextIOWrapper: ... @@ -381,11 +381,11 @@ else: def exists(self) -> bool: ... def read_text( self, - encoding: str | None = ..., - errors: str | None = ..., - newline: str | None = ..., - line_buffering: bool = ..., - write_through: bool = ..., + encoding: str | None = None, + errors: str | None = None, + newline: str | None = None, + line_buffering: bool = False, + write_through: bool = False, ) -> str: ... def read_bytes(self) -> bytes: ... if sys.version_info >= (3, 10): diff --git a/mypy/typeshed/stdlib/zipfile/_path/__init__.pyi b/mypy/typeshed/stdlib/zipfile/_path/__init__.pyi index 4c7b39ec4c6c..c936c4494c7c 100644 --- a/mypy/typeshed/stdlib/zipfile/_path/__init__.pyi +++ b/mypy/typeshed/stdlib/zipfile/_path/__init__.pyi @@ -52,8 +52,8 @@ if sys.version_info >= (3, 12): encoding: str | None = None, errors: str | None = None, newline: str | None = None, - line_buffering: bool = ..., - write_through: bool = ..., + line_buffering: bool = False, + write_through: bool = False, *, pwd: bytes | None = None, ) -> TextIOWrapper: ... @@ -65,11 +65,11 @@ if sys.version_info >= (3, 12): def exists(self) -> bool: ... def read_text( self, - encoding: str | None = ..., - errors: str | None = ..., - newline: str | None = ..., - line_buffering: bool = ..., - write_through: bool = ..., + encoding: str | None = None, + errors: str | None = None, + newline: str | None = None, + line_buffering: bool = False, + write_through: bool = False, ) -> str: ... def read_bytes(self) -> bytes: ... def joinpath(self, *other: StrPath) -> Path: ...