Skip to content

Sync typeshed #19585

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Aug 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
From 05f351f6a37fe8b73c698c348bf6aa5108363049 Mon Sep 17 00:00:00 2001
From 84a9d586544a0408d4654f57f83a93cb048070fb 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
Expand All @@ -8,15 +8,15 @@ 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 95ad6c7da..79e6cfde1 100644
index b9fa31139..3c3ba116a 100644
--- a/mypy/typeshed/stdlib/argparse.pyi
+++ b/mypy/typeshed/stdlib/argparse.pyi
@@ -2,7 +2,7 @@ import sys
from _typeshed import SupportsWrite, sentinel
from collections.abc import Callable, Generator, Iterable, Sequence
from re import Pattern
-from typing import IO, Any, ClassVar, Final, Generic, NoReturn, Protocol, TypeVar, overload
+from typing import IO, Any, ClassVar, Final, Generic, NewType, NoReturn, Protocol, TypeVar, overload
-from typing import IO, Any, ClassVar, Final, Generic, NoReturn, Protocol, TypeVar, overload, type_check_only
+from typing import IO, Any, ClassVar, Final, Generic, NewType, NoReturn, Protocol, TypeVar, overload, type_check_only
from typing_extensions import Self, TypeAlias, deprecated

__all__ = [
Expand All @@ -41,5 +41,5 @@ index 95ad6c7da..79e6cfde1 100644
default: Any = ...,
type: _ActionType = ...,
--
2.49.0
2.50.1

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
From 363d69b366695fea117631d30c348e36b9a5a99d Mon Sep 17 00:00:00 2001
From c217544146d36899d50e828d627652a0d8f63bb7 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
Expand All @@ -15,7 +15,7 @@ Subject: [PATCH] Revert Remove redundant inheritances from Iterator in
7 files changed, 34 insertions(+), 34 deletions(-)

diff --git a/mypy/typeshed/stdlib/_asyncio.pyi b/mypy/typeshed/stdlib/_asyncio.pyi
index 4544680cc..19a2d12d8 100644
index ed56f33af..5253e967e 100644
--- a/mypy/typeshed/stdlib/_asyncio.pyi
+++ b/mypy/typeshed/stdlib/_asyncio.pyi
@@ -1,6 +1,6 @@
Expand All @@ -36,10 +36,10 @@ index 4544680cc..19a2d12d8 100644
@property
def _exception(self) -> BaseException | None: ...
diff --git a/mypy/typeshed/stdlib/builtins.pyi b/mypy/typeshed/stdlib/builtins.pyi
index ea77a730f..900c4c93f 100644
index 0575be3c8..d9be595fe 100644
--- a/mypy/typeshed/stdlib/builtins.pyi
+++ b/mypy/typeshed/stdlib/builtins.pyi
@@ -1170,7 +1170,7 @@ class frozenset(AbstractSet[_T_co]):
@@ -1186,7 +1186,7 @@ class frozenset(AbstractSet[_T_co]):
def __hash__(self) -> int: ...
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...

Expand All @@ -48,7 +48,7 @@ index ea77a730f..900c4c93f 100644
def __new__(cls, iterable: Iterable[_T], start: int = 0) -> Self: ...
def __iter__(self) -> Self: ...
def __next__(self) -> tuple[int, _T]: ...
@@ -1366,7 +1366,7 @@ else:
@@ -1380,7 +1380,7 @@ else:

exit: _sitebuiltins.Quitter

Expand All @@ -57,7 +57,7 @@ index ea77a730f..900c4c93f 100644
@overload
def __new__(cls, function: None, iterable: Iterable[_T | None], /) -> Self: ...
@overload
@@ -1431,7 +1431,7 @@ license: _sitebuiltins._Printer
@@ -1444,7 +1444,7 @@ license: _sitebuiltins._Printer

def locals() -> dict[str, Any]: ...

Expand All @@ -66,7 +66,7 @@ index ea77a730f..900c4c93f 100644
# 3.14 adds `strict` argument.
if sys.version_info >= (3, 14):
@overload
@@ -1734,7 +1734,7 @@ def pow(base: _SupportsSomeKindOfPow, exp: complex, mod: None = None) -> complex
@@ -1750,7 +1750,7 @@ def pow(base: _SupportsSomeKindOfPow, exp: complex, mod: None = None) -> complex

quit: _sitebuiltins.Quitter

Expand All @@ -75,7 +75,7 @@ index ea77a730f..900c4c93f 100644
@overload
def __new__(cls, sequence: Reversible[_T], /) -> Iterator[_T]: ... # type: ignore[misc]
@overload
@@ -1795,7 +1795,7 @@ def vars(object: type, /) -> types.MappingProxyType[str, Any]: ...
@@ -1814,7 +1814,7 @@ def vars(object: type, /) -> types.MappingProxyType[str, Any]: ...
@overload
def vars(object: Any = ..., /) -> dict[str, Any]: ...

Expand Down Expand Up @@ -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 948b39ea1..1d5f9cf00 100644
index 910d63814..eb942bc55 100644
--- a/mypy/typeshed/stdlib/fileinput.pyi
+++ b/mypy/typeshed/stdlib/fileinput.pyi
@@ -1,8 +1,8 @@
Expand All @@ -116,12 +116,12 @@ index 948b39ea1..1d5f9cf00 100644
-from collections.abc import Callable, Iterable
+from collections.abc import Callable, Iterable, Iterator
from types import GenericAlias, TracebackType
-from typing import IO, Any, AnyStr, Generic, Literal, Protocol, overload
+from typing import IO, Any, AnyStr, Literal, Protocol, overload
-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

__all__ = [
@@ -104,7 +104,7 @@ def fileno() -> int: ...
@@ -105,7 +105,7 @@ def fileno() -> int: ...
def isfirstline() -> bool: ...
def isstdin() -> bool: ...

Expand Down Expand Up @@ -307,10 +307,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 5d3c2330b..ab783dbde 100644
index bcfea3a13..5a659deac 100644
--- a/mypy/typeshed/stdlib/sqlite3/__init__.pyi
+++ b/mypy/typeshed/stdlib/sqlite3/__init__.pyi
@@ -399,7 +399,7 @@ class Connection:
@@ -405,7 +405,7 @@ class Connection:
self, type: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None, /
) -> Literal[False]: ...

Expand All @@ -320,5 +320,5 @@ index 5d3c2330b..ab783dbde 100644
@property
def connection(self) -> Connection: ...
--
2.49.0
2.50.1

1 change: 1 addition & 0 deletions mypy/typeshed/stdlib/VERSIONS
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ compileall: 3.0-
compression: 3.14-
concurrent: 3.2-
concurrent.futures.interpreter: 3.14-
concurrent.interpreters: 3.14-
configparser: 3.0-
contextlib: 3.0-
contextvars: 3.7-
Expand Down
3 changes: 2 additions & 1 deletion mypy/typeshed/stdlib/_compression.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
from _typeshed import Incomplete, WriteableBuffer
from collections.abc import Callable
from io import DEFAULT_BUFFER_SIZE, BufferedIOBase, RawIOBase
from typing import Any, Protocol
from typing import Any, Protocol, type_check_only

BUFFER_SIZE = DEFAULT_BUFFER_SIZE

@type_check_only
class _Reader(Protocol):
def read(self, n: int, /) -> bytes: ...
def seekable(self) -> bool: ...
Expand Down
5 changes: 4 additions & 1 deletion mypy/typeshed/stdlib/_ctypes.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ class _SimpleCData(_CData, Generic[_T], metaclass=_PyCSimpleType):
def __init__(self, value: _T = ...) -> None: ... # pyright: ignore[reportInvalidTypeVarUse]
def __ctypes_from_outparam__(self, /) -> _T: ... # type: ignore[override]

@type_check_only
class _CanCastTo(_CData): ...

@type_check_only
class _PointerLike(_CanCastTo): ...

# This type is not exposed. It calls itself _ctypes.PyCPointerType.
Expand All @@ -114,7 +117,7 @@ class _PyCPointerType(_CTypeBaseType):
def from_buffer_copy(self: type[_typeshed.Self], buffer: ReadableBuffer, offset: int = 0, /) -> _typeshed.Self: ...
def from_param(self: type[_typeshed.Self], value: Any, /) -> _typeshed.Self | _CArgObject: ...
def in_dll(self: type[_typeshed.Self], dll: CDLL, name: str, /) -> _typeshed.Self: ...
def set_type(self, type: Any, /) -> None: ...
def set_type(self, type: _CTypeBaseType, /) -> None: ...
if sys.version_info < (3, 13):
# Inherited from CType_Type starting on 3.13
def __mul__(cls: type[_CT], other: int) -> type[Array[_CT]]: ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues]
Expand Down
3 changes: 2 additions & 1 deletion mypy/typeshed/stdlib/_gdbm.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import sys
from _typeshed import ReadOnlyBuffer, StrOrBytesPath
from types import TracebackType
from typing import TypeVar, overload
from typing import TypeVar, overload, type_check_only
from typing_extensions import Self, TypeAlias

if sys.platform != "win32":
Expand All @@ -13,6 +13,7 @@ if sys.platform != "win32":

class error(OSError): ...
# Actual typename gdbm, not exposed by the implementation
@type_check_only
class _gdbm:
def firstkey(self) -> bytes | None: ...
def nextkey(self, key: _KeyType) -> bytes | None: ...
Expand Down
9 changes: 4 additions & 5 deletions mypy/typeshed/stdlib/_heapq.pyi
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import sys
from typing import Any, Final, TypeVar

_T = TypeVar("_T") # list items must be comparable
from _typeshed import SupportsRichComparisonT as _T # All type variable use in this module requires comparability.
from typing import Final

__about__: Final[str]

def heapify(heap: list[Any], /) -> None: ... # list items must be comparable
def heapify(heap: list[_T], /) -> None: ...
def heappop(heap: list[_T], /) -> _T: ...
def heappush(heap: list[_T], item: _T, /) -> None: ...
def heappushpop(heap: list[_T], item: _T, /) -> _T: ...
def heapreplace(heap: list[_T], item: _T, /) -> _T: ...

if sys.version_info >= (3, 14):
def heapify_max(heap: list[Any], /) -> None: ... # list items must be comparable
def heapify_max(heap: list[_T], /) -> None: ...
def heappop_max(heap: list[_T], /) -> _T: ...
def heappush_max(heap: list[_T], item: _T, /) -> None: ...
def heappushpop_max(heap: list[_T], item: _T, /) -> _T: ...
Expand Down
11 changes: 7 additions & 4 deletions mypy/typeshed/stdlib/_interpreters.pyi
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import types
from collections.abc import Callable
from typing import Any, Final, Literal, SupportsIndex
from typing import Any, Final, Literal, SupportsIndex, TypeVar
from typing_extensions import TypeAlias

_R = TypeVar("_R")

_Configs: TypeAlias = Literal["default", "isolated", "legacy", "empty", ""]
_SharedDict: TypeAlias = dict[str, Any] # many objects can be shared

Expand All @@ -21,7 +23,7 @@ def get_current() -> tuple[int, int]: ...
def get_main() -> tuple[int, int]: ...
def is_running(id: SupportsIndex, *, restrict: bool = False) -> bool: ...
def get_config(id: SupportsIndex, *, restrict: bool = False) -> types.SimpleNamespace: ...
def whence(id: SupportsIndex) -> int: ...
def whence(id: SupportsIndex) -> _Whence: ...
def exec(
id: SupportsIndex,
code: str | types.CodeType | Callable[[], object],
Expand All @@ -31,12 +33,12 @@ def exec(
) -> None | types.SimpleNamespace: ...
def call(
id: SupportsIndex,
callable: Callable[..., object],
callable: Callable[..., _R],
args: tuple[object, ...] | None = None,
kwargs: dict[str, object] | None = None,
*,
restrict: bool = False,
) -> object: ...
) -> tuple[_R, types.SimpleNamespace]: ...
def run_string(
id: SupportsIndex,
script: str | types.CodeType | Callable[[], object],
Expand All @@ -53,6 +55,7 @@ def decref(id: SupportsIndex, *, restrict: bool = False) -> None: ...
def is_shareable(obj: object) -> bool: ...
def capture_exception(exc: BaseException | None = None) -> types.SimpleNamespace: ...

_Whence: TypeAlias = Literal[0, 1, 2, 3, 4, 5]
WHENCE_UNKNOWN: Final = 0
WHENCE_RUNTIME: Final = 1
WHENCE_LEGACY_CAPI: Final = 2
Expand Down
1 change: 1 addition & 0 deletions mypy/typeshed/stdlib/_io.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class BytesIO(BufferedIOBase, _BufferedIOBase, BinaryIO): # type: ignore[misc]
def readlines(self, size: int | None = None, /) -> list[bytes]: ...
def seek(self, pos: int, whence: int = 0, /) -> int: ...

@type_check_only
class _BufferedReaderStream(Protocol):
def read(self, n: int = ..., /) -> bytes: ...
# Optional: def readall(self) -> bytes: ...
Expand Down
2 changes: 1 addition & 1 deletion mypy/typeshed/stdlib/_json.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ class make_scanner:

def encode_basestring(s: str, /) -> str: ...
def encode_basestring_ascii(s: str, /) -> str: ...
def scanstring(string: str, end: int, strict: bool = ...) -> tuple[str, int]: ...
def scanstring(string: str, end: int, strict: bool = True) -> tuple[str, int]: ...
5 changes: 5 additions & 0 deletions mypy/typeshed/stdlib/_msi.pyi
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import sys
from typing import type_check_only

if sys.platform == "win32":
class MSIError(Exception): ...
# Actual typename View, not exposed by the implementation
@type_check_only
class _View:
def Execute(self, params: _Record | None = ...) -> None: ...
def GetColumnInfo(self, kind: int) -> _Record: ...
Expand All @@ -14,6 +16,7 @@ if sys.platform == "win32":
__init__: None # type: ignore[assignment]

# Actual typename SummaryInformation, not exposed by the implementation
@type_check_only
class _SummaryInformation:
def GetProperty(self, field: int) -> int | bytes | None: ...
def GetPropertyCount(self) -> int: ...
Expand All @@ -24,6 +27,7 @@ if sys.platform == "win32":
__init__: None # type: ignore[assignment]

# Actual typename Database, not exposed by the implementation
@type_check_only
class _Database:
def OpenView(self, sql: str) -> _View: ...
def Commit(self) -> None: ...
Expand All @@ -34,6 +38,7 @@ if sys.platform == "win32":
__init__: None # type: ignore[assignment]

# Actual typename Record, not exposed by the implementation
@type_check_only
class _Record:
def GetFieldCount(self) -> int: ...
def GetInteger(self, field: int) -> int: ...
Expand Down
9 changes: 8 additions & 1 deletion mypy/typeshed/stdlib/_operator.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import sys
from _typeshed import SupportsGetItem
from collections.abc import Callable, Container, Iterable, MutableMapping, MutableSequence, Sequence
from operator import attrgetter as attrgetter, itemgetter as itemgetter, methodcaller as methodcaller
from typing import Any, AnyStr, Protocol, SupportsAbs, SupportsIndex, TypeVar, overload
from typing import Any, AnyStr, Protocol, SupportsAbs, SupportsIndex, TypeVar, overload, type_check_only
from typing_extensions import ParamSpec, TypeAlias, TypeIs

_R = TypeVar("_R")
Expand All @@ -16,26 +16,33 @@ _P = ParamSpec("_P")
# operators can be overloaded to return an arbitrary object. For example,
# the numpy.array comparison dunders return another numpy.array.

@type_check_only
class _SupportsDunderLT(Protocol):
def __lt__(self, other: Any, /) -> Any: ...

@type_check_only
class _SupportsDunderGT(Protocol):
def __gt__(self, other: Any, /) -> Any: ...

@type_check_only
class _SupportsDunderLE(Protocol):
def __le__(self, other: Any, /) -> Any: ...

@type_check_only
class _SupportsDunderGE(Protocol):
def __ge__(self, other: Any, /) -> Any: ...

_SupportsComparison: TypeAlias = _SupportsDunderLE | _SupportsDunderGE | _SupportsDunderGT | _SupportsDunderLT

@type_check_only
class _SupportsInversion(Protocol[_T_co]):
def __invert__(self) -> _T_co: ...

@type_check_only
class _SupportsNeg(Protocol[_T_co]):
def __neg__(self) -> _T_co: ...

@type_check_only
class _SupportsPos(Protocol[_T_co]):
def __pos__(self) -> _T_co: ...

Expand Down
1 change: 1 addition & 0 deletions mypy/typeshed/stdlib/_pickle.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ from pickle import PickleBuffer as PickleBuffer
from typing import Any, Protocol, type_check_only
from typing_extensions import TypeAlias

@type_check_only
class _ReadableFileobj(Protocol):
def read(self, n: int, /) -> bytes: ...
def readline(self) -> bytes: ...
Expand Down
Loading
Loading