Skip to content

Commit e089abc

Browse files
Sync typeshed (#20415)
Source commit: python/typeshed@2f3c3b7 --------- Co-authored-by: Shantanu <[email protected]> Co-authored-by: hauntsaninja <[email protected]>
1 parent 65f35f9 commit e089abc

File tree

20 files changed

+208
-89
lines changed

20 files changed

+208
-89
lines changed

mypy/typeshed/stdlib/_ctypes.pyi

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ from abc import abstractmethod
55
from collections.abc import Callable, Iterable, Iterator, Mapping, Sequence
66
from ctypes import CDLL, ArgumentError as ArgumentError, c_void_p
77
from types import GenericAlias
8-
from typing import Any, ClassVar, Final, Generic, TypeVar, final, overload, type_check_only
8+
from typing import Any, ClassVar, Final, Generic, Literal, TypeVar, final, overload, type_check_only
99
from typing_extensions import Self, TypeAlias
1010

1111
_T = TypeVar("_T")
@@ -266,6 +266,10 @@ class Structure(_CData, metaclass=_PyCStructType):
266266
if sys.version_info >= (3, 13):
267267
_align_: ClassVar[int]
268268

269+
if sys.version_info >= (3, 14):
270+
# _layout_ can be defined by the user, but is not always present.
271+
_layout_: ClassVar[Literal["ms", "gcc-sysv"]]
272+
269273
def __init__(self, *args: Any, **kw: Any) -> None: ...
270274
def __getattr__(self, name: str) -> Any: ...
271275
def __setattr__(self, name: str, value: Any) -> None: ...

mypy/typeshed/stdlib/_winapi.pyi

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,9 @@ if sys.platform == "win32":
192192
template_file: int,
193193
/,
194194
) -> int: ...
195+
def CreateFileMapping(
196+
file_handle: int, security_attributes: int, protect: int, max_size_high: int, max_size_low: int, name: str, /
197+
) -> int: ...
195198
def CreateJunction(src_path: str, dst_path: str, /) -> None: ...
196199
def CreateNamedPipe(
197200
name: str,
@@ -235,6 +238,9 @@ if sys.platform == "win32":
235238
def GetModuleFileName(module_handle: int, /) -> str: ...
236239
def GetStdHandle(std_handle: int, /) -> int: ...
237240
def GetVersion() -> int: ...
241+
def MapViewOfFile(
242+
file_map: int, desired_access: int, file_offset_high: int, file_offset_low: int, number_bytes: int, /
243+
) -> int: ...
238244
def OpenProcess(desired_access: int, inherit_handle: bool, process_id: int, /) -> int: ...
239245
def PeekNamedPipe(handle: int, size: int = 0, /) -> tuple[int, int] | tuple[bytes, int, int]: ...
240246
if sys.version_info >= (3, 10):
@@ -251,6 +257,7 @@ if sys.platform == "win32":
251257
named_pipe: int, mode: int | None, max_collection_count: int | None, collect_data_timeout: int | None, /
252258
) -> None: ...
253259
def TerminateProcess(handle: int, exit_code: int, /) -> None: ...
260+
def VirtualQuerySize(address: int, /) -> int: ...
254261
def WaitForMultipleObjects(handle_seq: Sequence[int], wait_flag: bool, milliseconds: int = 0xFFFFFFFF, /) -> int: ...
255262
def WaitForSingleObject(handle: int, milliseconds: int, /) -> int: ...
256263
def WaitNamedPipe(name: str, timeout: int, /) -> None: ...
@@ -281,6 +288,8 @@ if sys.platform == "win32":
281288
def ResetEvent(event: int) -> None: ...
282289
def SetEvent(event: int) -> None: ...
283290

291+
def OpenFileMapping(desired_access: int, inherit_handle: bool, name: str, /) -> int: ...
292+
284293
if sys.version_info >= (3, 12):
285294
def CopyFile2(existing_file_name: str, new_file_name: str, flags: int, progress_routine: int | None = None) -> int: ...
286295
def NeedCurrentDirectoryForExePath(exe_name: str, /) -> bool: ...

mypy/typeshed/stdlib/_zstd.pyi

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ class ZstdCompressor:
4646
FLUSH_BLOCK: Final = 1
4747
FLUSH_FRAME: Final = 2
4848
def __new__(
49-
cls, level: int | None = None, options: Mapping[int, int] | None = None, zstd_dict: ZstdDict | None = None
49+
cls,
50+
level: int | None = None,
51+
options: Mapping[int, int] | None = None,
52+
zstd_dict: ZstdDict | tuple[ZstdDict, int] | None = None,
5053
) -> Self: ...
5154
def compress(
5255
self, /, data: ReadableBuffer, mode: _ZstdCompressorContinue | _ZstdCompressorFlushBlock | _ZstdCompressorFlushFrame = 0
@@ -58,7 +61,9 @@ class ZstdCompressor:
5861

5962
@final
6063
class ZstdDecompressor:
61-
def __new__(cls, zstd_dict: ZstdDict | None = None, options: Mapping[int, int] | None = None) -> Self: ...
64+
def __new__(
65+
cls, zstd_dict: ZstdDict | tuple[ZstdDict, int] | None = None, options: Mapping[int, int] | None = None
66+
) -> Self: ...
6267
def decompress(self, /, data: ReadableBuffer, max_length: int = -1) -> bytes: ...
6368
@property
6469
def eof(self) -> bool: ...

mypy/typeshed/stdlib/argparse.pyi

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,11 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
251251
def _read_args_from_files(self, arg_strings: list[str]) -> list[str]: ...
252252
def _match_argument(self, action: Action, arg_strings_pattern: str) -> int: ...
253253
def _match_arguments_partial(self, actions: Sequence[Action], arg_strings_pattern: str) -> list[int]: ...
254-
def _parse_optional(self, arg_string: str) -> tuple[Action | None, str, str | None] | None: ...
254+
if sys.version_info >= (3, 12):
255+
def _parse_optional(self, arg_string: str) -> list[tuple[Action | None, str, str | None, str | None]] | None: ...
256+
else:
257+
def _parse_optional(self, arg_string: str) -> tuple[Action | None, str, str | None] | None: ...
258+
255259
def _get_option_tuples(self, option_string: str) -> list[tuple[Action, str, str | None]]: ...
256260
def _get_nargs_pattern(self, action: Action) -> str: ...
257261
def _get_values(self, action: Action, arg_strings: list[str]) -> Any: ...

mypy/typeshed/stdlib/builtins.pyi

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -633,8 +633,13 @@ class bytes(Sequence[int]):
633633
def translate(self, table: ReadableBuffer | None, /, delete: ReadableBuffer = b"") -> bytes: ...
634634
def upper(self) -> bytes: ...
635635
def zfill(self, width: SupportsIndex, /) -> bytes: ...
636-
@classmethod
637-
def fromhex(cls, string: str, /) -> Self: ...
636+
if sys.version_info >= (3, 14):
637+
@classmethod
638+
def fromhex(cls, string: str | ReadableBuffer, /) -> Self: ...
639+
else:
640+
@classmethod
641+
def fromhex(cls, string: str, /) -> Self: ...
642+
638643
@staticmethod
639644
def maketrans(frm: ReadableBuffer, to: ReadableBuffer, /) -> bytes: ...
640645
def __len__(self) -> int: ...
@@ -738,8 +743,13 @@ class bytearray(MutableSequence[int]):
738743
def translate(self, table: ReadableBuffer | None, /, delete: bytes = b"") -> bytearray: ...
739744
def upper(self) -> bytearray: ...
740745
def zfill(self, width: SupportsIndex, /) -> bytearray: ...
741-
@classmethod
742-
def fromhex(cls, string: str, /) -> Self: ...
746+
if sys.version_info >= (3, 14):
747+
@classmethod
748+
def fromhex(cls, string: str | ReadableBuffer, /) -> Self: ...
749+
else:
750+
@classmethod
751+
def fromhex(cls, string: str, /) -> Self: ...
752+
743753
@staticmethod
744754
def maketrans(frm: ReadableBuffer, to: ReadableBuffer, /) -> bytes: ...
745755
def __len__(self) -> int: ...
@@ -846,11 +856,15 @@ class memoryview(Sequence[_I]):
846856
def hex(self, sep: str | bytes = ..., bytes_per_sep: SupportsIndex = 1) -> str: ...
847857
def __buffer__(self, flags: int, /) -> memoryview: ...
848858
def __release_buffer__(self, buffer: memoryview, /) -> None: ...
859+
if sys.version_info >= (3, 14):
860+
def index(self, value: object, start: SupportsIndex = 0, stop: SupportsIndex = sys.maxsize, /) -> int: ...
861+
def count(self, value: object, /) -> int: ...
862+
else:
863+
# These are inherited from the Sequence ABC, but don't actually exist on memoryview.
864+
# See https://github.com/python/cpython/issues/125420
865+
index: ClassVar[None] # type: ignore[assignment]
866+
count: ClassVar[None] # type: ignore[assignment]
849867

850-
# These are inherited from the Sequence ABC, but don't actually exist on memoryview.
851-
# See https://github.com/python/cpython/issues/125420
852-
index: ClassVar[None] # type: ignore[assignment]
853-
count: ClassVar[None] # type: ignore[assignment]
854868
if sys.version_info >= (3, 14):
855869
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
856870

mypy/typeshed/stdlib/compression/zstd/__init__.pyi

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,14 @@ def get_frame_info(frame_buffer: ReadableBuffer) -> FrameInfo: ...
4444
def train_dict(samples: Iterable[ReadableBuffer], dict_size: int) -> ZstdDict: ...
4545
def finalize_dict(zstd_dict: ZstdDict, /, samples: Iterable[ReadableBuffer], dict_size: int, level: int) -> ZstdDict: ...
4646
def compress(
47-
data: ReadableBuffer, level: int | None = None, options: Mapping[int, int] | None = None, zstd_dict: ZstdDict | None = None
47+
data: ReadableBuffer,
48+
level: int | None = None,
49+
options: Mapping[int, int] | None = None,
50+
zstd_dict: ZstdDict | tuple[ZstdDict, int] | None = None,
51+
) -> bytes: ...
52+
def decompress(
53+
data: ReadableBuffer, zstd_dict: ZstdDict | tuple[ZstdDict, int] | None = None, options: Mapping[int, int] | None = None
4854
) -> bytes: ...
49-
def decompress(data: ReadableBuffer, zstd_dict: ZstdDict | None = None, options: Mapping[int, int] | None = None) -> bytes: ...
5055
@final
5156
class CompressionParameter(enum.IntEnum):
5257
compression_level = _zstd.ZSTD_c_compressionLevel

mypy/typeshed/stdlib/compression/zstd/_zstdfile.pyi

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class ZstdFile(_streams.BaseStream):
3636
*,
3737
level: None = None,
3838
options: Mapping[int, int] | None = None,
39-
zstd_dict: ZstdDict | None = None,
39+
zstd_dict: ZstdDict | tuple[ZstdDict, int] | None = None,
4040
) -> None: ...
4141
@overload
4242
def __init__(
@@ -47,7 +47,7 @@ class ZstdFile(_streams.BaseStream):
4747
*,
4848
level: int | None = None,
4949
options: Mapping[int, int] | None = None,
50-
zstd_dict: ZstdDict | None = None,
50+
zstd_dict: ZstdDict | tuple[ZstdDict, int] | None = None,
5151
) -> None: ...
5252
def write(self, data: ReadableBuffer, /) -> int: ...
5353
def flush(self, mode: _ZstdCompressorFlushBlock | _ZstdCompressorFlushFrame = 1) -> bytes: ... # type: ignore[override]
@@ -71,7 +71,7 @@ def open(
7171
*,
7272
level: None = None,
7373
options: Mapping[int, int] | None = None,
74-
zstd_dict: ZstdDict | None = None,
74+
zstd_dict: ZstdDict | tuple[ZstdDict, int] | None = None,
7575
encoding: str | None = None,
7676
errors: str | None = None,
7777
newline: str | None = None,
@@ -84,7 +84,7 @@ def open(
8484
*,
8585
level: int | None = None,
8686
options: Mapping[int, int] | None = None,
87-
zstd_dict: ZstdDict | None = None,
87+
zstd_dict: ZstdDict | tuple[ZstdDict, int] | None = None,
8888
encoding: str | None = None,
8989
errors: str | None = None,
9090
newline: str | None = None,
@@ -97,7 +97,7 @@ def open(
9797
*,
9898
level: None = None,
9999
options: Mapping[int, int] | None = None,
100-
zstd_dict: ZstdDict | None = None,
100+
zstd_dict: ZstdDict | tuple[ZstdDict, int] | None = None,
101101
encoding: str | None = None,
102102
errors: str | None = None,
103103
newline: str | None = None,
@@ -110,7 +110,7 @@ def open(
110110
*,
111111
level: int | None = None,
112112
options: Mapping[int, int] | None = None,
113-
zstd_dict: ZstdDict | None = None,
113+
zstd_dict: ZstdDict | tuple[ZstdDict, int] | None = None,
114114
encoding: str | None = None,
115115
errors: str | None = None,
116116
newline: str | None = None,

mypy/typeshed/stdlib/heapq.pyi

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1+
import sys
12
from _heapq import *
23
from _typeshed import SupportsRichComparison
34
from collections.abc import Callable, Generator, Iterable
45
from typing import Any, Final, TypeVar
56

67
__all__ = ["heappush", "heappop", "heapify", "heapreplace", "merge", "nlargest", "nsmallest", "heappushpop"]
78

9+
if sys.version_info >= (3, 14):
10+
# Added to __all__ in 3.14.1
11+
__all__ += ["heapify_max", "heappop_max", "heappush_max", "heappushpop_max", "heapreplace_max"]
12+
813
_S = TypeVar("_S")
914

1015
__about__: Final[str]

mypy/typeshed/stdlib/importlib/readers.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ if sys.version_info >= (3, 10):
5252
def is_file(self) -> Literal[False]: ...
5353

5454
if sys.version_info >= (3, 12):
55-
def joinpath(self, *descendants: str) -> abc.Traversable: ...
55+
def joinpath(self, *descendants: StrPath) -> abc.Traversable: ...
5656
elif sys.version_info >= (3, 11):
57-
def joinpath(self, child: str) -> abc.Traversable: ... # type: ignore[override]
57+
def joinpath(self, child: StrPath) -> abc.Traversable: ... # type: ignore[override]
5858
else:
5959
def joinpath(self, child: str) -> abc.Traversable: ...
6060

mypy/typeshed/stdlib/importlib/resources/abc.pyi

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import sys
2+
from _typeshed import StrPath
23
from abc import ABCMeta, abstractmethod
34
from collections.abc import Iterator
45
from io import BufferedReader
@@ -24,7 +25,7 @@ if sys.version_info >= (3, 11):
2425
@abstractmethod
2526
def iterdir(self) -> Iterator[Traversable]: ...
2627
@abstractmethod
27-
def joinpath(self, *descendants: str) -> Traversable: ...
28+
def joinpath(self, *descendants: StrPath) -> Traversable: ...
2829

2930
# The documentation and runtime protocol allows *args, **kwargs arguments,
3031
# but this would mean that all implementers would have to support them,
@@ -38,7 +39,7 @@ if sys.version_info >= (3, 11):
3839
@property
3940
@abstractmethod
4041
def name(self) -> str: ...
41-
def __truediv__(self, child: str, /) -> Traversable: ...
42+
def __truediv__(self, child: StrPath, /) -> Traversable: ...
4243
@abstractmethod
4344
def read_bytes(self) -> bytes: ...
4445
@abstractmethod

0 commit comments

Comments
 (0)