Skip to content

Commit 5c196d1

Browse files
Sync typeshed (#19301)
Source commit: python/typeshed@ecd5141
1 parent ce5f127 commit 5c196d1

21 files changed

+482
-77
lines changed

mypy/typeshed/stdlib/VERSIONS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ _warnings: 3.0-
7676
_weakref: 3.0-
7777
_weakrefset: 3.0-
7878
_winapi: 3.3-
79+
_zstd: 3.14-
7980
abc: 3.0-
8081
aifc: 3.0-3.12
8182
annotationlib: 3.14-

mypy/typeshed/stdlib/_hashlib.pyi

Lines changed: 57 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,63 @@ def compare_digest(a: ReadableBuffer, b: ReadableBuffer, /) -> bool: ...
6060
def compare_digest(a: AnyStr, b: AnyStr, /) -> bool: ...
6161
def get_fips_mode() -> int: ...
6262
def hmac_new(key: bytes | bytearray, msg: ReadableBuffer = b"", digestmod: _DigestMod = None) -> HMAC: ...
63-
def new(name: str, string: ReadableBuffer = b"", *, usedforsecurity: bool = True) -> HASH: ...
64-
def openssl_md5(string: ReadableBuffer = b"", *, usedforsecurity: bool = True) -> HASH: ...
65-
def openssl_sha1(string: ReadableBuffer = b"", *, usedforsecurity: bool = True) -> HASH: ...
66-
def openssl_sha224(string: ReadableBuffer = b"", *, usedforsecurity: bool = True) -> HASH: ...
67-
def openssl_sha256(string: ReadableBuffer = b"", *, usedforsecurity: bool = True) -> HASH: ...
68-
def openssl_sha384(string: ReadableBuffer = b"", *, usedforsecurity: bool = True) -> HASH: ...
69-
def openssl_sha512(string: ReadableBuffer = b"", *, usedforsecurity: bool = True) -> HASH: ...
70-
def openssl_sha3_224(string: ReadableBuffer = b"", *, usedforsecurity: bool = True) -> HASH: ...
71-
def openssl_sha3_256(string: ReadableBuffer = b"", *, usedforsecurity: bool = True) -> HASH: ...
72-
def openssl_sha3_384(string: ReadableBuffer = b"", *, usedforsecurity: bool = True) -> HASH: ...
73-
def openssl_sha3_512(string: ReadableBuffer = b"", *, usedforsecurity: bool = True) -> HASH: ...
74-
def openssl_shake_128(string: ReadableBuffer = b"", *, usedforsecurity: bool = True) -> HASHXOF: ...
75-
def openssl_shake_256(string: ReadableBuffer = b"", *, usedforsecurity: bool = True) -> HASHXOF: ...
63+
64+
if sys.version_info >= (3, 13):
65+
def new(
66+
name: str, data: ReadableBuffer = b"", *, usedforsecurity: bool = True, string: ReadableBuffer | None = None
67+
) -> HASH: ...
68+
def openssl_md5(
69+
data: ReadableBuffer = b"", *, usedforsecurity: bool = True, string: ReadableBuffer | None = None
70+
) -> HASH: ...
71+
def openssl_sha1(
72+
data: ReadableBuffer = b"", *, usedforsecurity: bool = True, string: ReadableBuffer | None = None
73+
) -> HASH: ...
74+
def openssl_sha224(
75+
data: ReadableBuffer = b"", *, usedforsecurity: bool = True, string: ReadableBuffer | None = None
76+
) -> HASH: ...
77+
def openssl_sha256(
78+
data: ReadableBuffer = b"", *, usedforsecurity: bool = True, string: ReadableBuffer | None = None
79+
) -> HASH: ...
80+
def openssl_sha384(
81+
data: ReadableBuffer = b"", *, usedforsecurity: bool = True, string: ReadableBuffer | None = None
82+
) -> HASH: ...
83+
def openssl_sha512(
84+
data: ReadableBuffer = b"", *, usedforsecurity: bool = True, string: ReadableBuffer | None = None
85+
) -> HASH: ...
86+
def openssl_sha3_224(
87+
data: ReadableBuffer = b"", *, usedforsecurity: bool = True, string: ReadableBuffer | None = None
88+
) -> HASH: ...
89+
def openssl_sha3_256(
90+
data: ReadableBuffer = b"", *, usedforsecurity: bool = True, string: ReadableBuffer | None = None
91+
) -> HASH: ...
92+
def openssl_sha3_384(
93+
data: ReadableBuffer = b"", *, usedforsecurity: bool = True, string: ReadableBuffer | None = None
94+
) -> HASH: ...
95+
def openssl_sha3_512(
96+
data: ReadableBuffer = b"", *, usedforsecurity: bool = True, string: ReadableBuffer | None = None
97+
) -> HASH: ...
98+
def openssl_shake_128(
99+
data: ReadableBuffer = b"", *, usedforsecurity: bool = True, string: ReadableBuffer | None = None
100+
) -> HASHXOF: ...
101+
def openssl_shake_256(
102+
data: ReadableBuffer = b"", *, usedforsecurity: bool = True, string: ReadableBuffer | None = None
103+
) -> HASHXOF: ...
104+
105+
else:
106+
def new(name: str, string: ReadableBuffer = b"", *, usedforsecurity: bool = True) -> HASH: ...
107+
def openssl_md5(string: ReadableBuffer = b"", *, usedforsecurity: bool = True) -> HASH: ...
108+
def openssl_sha1(string: ReadableBuffer = b"", *, usedforsecurity: bool = True) -> HASH: ...
109+
def openssl_sha224(string: ReadableBuffer = b"", *, usedforsecurity: bool = True) -> HASH: ...
110+
def openssl_sha256(string: ReadableBuffer = b"", *, usedforsecurity: bool = True) -> HASH: ...
111+
def openssl_sha384(string: ReadableBuffer = b"", *, usedforsecurity: bool = True) -> HASH: ...
112+
def openssl_sha512(string: ReadableBuffer = b"", *, usedforsecurity: bool = True) -> HASH: ...
113+
def openssl_sha3_224(string: ReadableBuffer = b"", *, usedforsecurity: bool = True) -> HASH: ...
114+
def openssl_sha3_256(string: ReadableBuffer = b"", *, usedforsecurity: bool = True) -> HASH: ...
115+
def openssl_sha3_384(string: ReadableBuffer = b"", *, usedforsecurity: bool = True) -> HASH: ...
116+
def openssl_sha3_512(string: ReadableBuffer = b"", *, usedforsecurity: bool = True) -> HASH: ...
117+
def openssl_shake_128(string: ReadableBuffer = b"", *, usedforsecurity: bool = True) -> HASHXOF: ...
118+
def openssl_shake_256(string: ReadableBuffer = b"", *, usedforsecurity: bool = True) -> HASHXOF: ...
119+
76120
def hmac_digest(key: bytes | bytearray, msg: ReadableBuffer, digest: str) -> bytes: ...
77121
def pbkdf2_hmac(
78122
hash_name: str, password: ReadableBuffer, salt: ReadableBuffer, iterations: int, dklen: int | None = None

mypy/typeshed/stdlib/_socket.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,8 @@ if sys.platform != "win32":
229229
IP_RECVOPTS: int
230230
IP_RECVRETOPTS: int
231231
IP_RETOPTS: int
232+
if sys.version_info >= (3, 13) and sys.platform == "linux":
233+
CAN_RAW_ERR_FILTER: int
232234
if sys.version_info >= (3, 14):
233235
IP_RECVTTL: int
234236

@@ -246,7 +248,6 @@ if sys.version_info >= (3, 14):
246248
TCP_QUICKACK: int
247249

248250
if sys.platform == "linux":
249-
CAN_RAW_ERR_FILTER: int
250251
IP_FREEBIND: int
251252
IP_RECVORIGDSTADDR: int
252253
VMADDR_CID_LOCAL: int

mypy/typeshed/stdlib/_zstd.pyi

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
from _typeshed import ReadableBuffer
2+
from collections.abc import Mapping
3+
from compression.zstd import CompressionParameter, DecompressionParameter
4+
from typing import Final, Literal, final
5+
from typing_extensions import Self, TypeAlias
6+
7+
ZSTD_CLEVEL_DEFAULT: Final = 3
8+
ZSTD_DStreamOutSize: Final = 131072
9+
ZSTD_btlazy2: Final = 6
10+
ZSTD_btopt: Final = 7
11+
ZSTD_btultra: Final = 8
12+
ZSTD_btultra2: Final = 9
13+
ZSTD_c_chainLog: Final = 103
14+
ZSTD_c_checksumFlag: Final = 201
15+
ZSTD_c_compressionLevel: Final = 100
16+
ZSTD_c_contentSizeFlag: Final = 200
17+
ZSTD_c_dictIDFlag: Final = 202
18+
ZSTD_c_enableLongDistanceMatching: Final = 160
19+
ZSTD_c_hashLog: Final = 102
20+
ZSTD_c_jobSize: Final = 401
21+
ZSTD_c_ldmBucketSizeLog: Final = 163
22+
ZSTD_c_ldmHashLog: Final = 161
23+
ZSTD_c_ldmHashRateLog: Final = 164
24+
ZSTD_c_ldmMinMatch: Final = 162
25+
ZSTD_c_minMatch: Final = 105
26+
ZSTD_c_nbWorkers: Final = 400
27+
ZSTD_c_overlapLog: Final = 402
28+
ZSTD_c_searchLog: Final = 104
29+
ZSTD_c_strategy: Final = 107
30+
ZSTD_c_targetLength: Final = 106
31+
ZSTD_c_windowLog: Final = 101
32+
ZSTD_d_windowLogMax: Final = 100
33+
ZSTD_dfast: Final = 2
34+
ZSTD_fast: Final = 1
35+
ZSTD_greedy: Final = 3
36+
ZSTD_lazy: Final = 4
37+
ZSTD_lazy2: Final = 5
38+
39+
_ZstdCompressorContinue: TypeAlias = Literal[0]
40+
_ZstdCompressorFlushBlock: TypeAlias = Literal[1]
41+
_ZstdCompressorFlushFrame: TypeAlias = Literal[2]
42+
43+
@final
44+
class ZstdCompressor:
45+
CONTINUE: Final = 0
46+
FLUSH_BLOCK: Final = 1
47+
FLUSH_FRAME: Final = 2
48+
def __init__(
49+
self, level: int | None = None, options: Mapping[int, int] | None = None, zstd_dict: ZstdDict | None = None
50+
) -> None: ...
51+
def compress(
52+
self, /, data: ReadableBuffer, mode: _ZstdCompressorContinue | _ZstdCompressorFlushBlock | _ZstdCompressorFlushFrame = 0
53+
) -> bytes: ...
54+
def flush(self, /, mode: _ZstdCompressorFlushBlock | _ZstdCompressorFlushFrame = 2) -> bytes: ...
55+
@property
56+
def last_mode(self) -> _ZstdCompressorContinue | _ZstdCompressorFlushBlock | _ZstdCompressorFlushFrame: ...
57+
58+
@final
59+
class ZstdDecompressor:
60+
def __init__(self, zstd_dict: ZstdDict | None = None, options: Mapping[int, int] | None = None) -> None: ...
61+
def decompress(self, /, data: ReadableBuffer, max_length: int = -1) -> bytes: ...
62+
@property
63+
def eof(self) -> bool: ...
64+
@property
65+
def needs_input(self) -> bool: ...
66+
@property
67+
def unused_data(self) -> bytes: ...
68+
69+
@final
70+
class ZstdDict:
71+
def __init__(self, dict_content: bytes, /, *, is_raw: bool = False) -> None: ...
72+
def __len__(self, /) -> int: ...
73+
@property
74+
def as_digested_dict(self) -> tuple[Self, int]: ...
75+
@property
76+
def as_prefix(self) -> tuple[Self, int]: ...
77+
@property
78+
def as_undigested_dict(self) -> tuple[Self, int]: ...
79+
@property
80+
def dict_content(self) -> bytes: ...
81+
@property
82+
def dict_id(self) -> int: ...
83+
84+
class ZstdError(Exception): ...
85+
86+
def finalize_dict(
87+
custom_dict_bytes: bytes, samples_bytes: bytes, samples_sizes: tuple[int, ...], dict_size: int, compression_level: int, /
88+
) -> bytes: ...
89+
def get_frame_info(frame_buffer: ReadableBuffer) -> tuple[int, int]: ...
90+
def get_frame_size(frame_buffer: ReadableBuffer) -> int: ...
91+
def get_param_bounds(parameter: int, is_compress: bool) -> tuple[int, int]: ...
92+
def set_parameter_types(c_parameter_type: type[CompressionParameter], d_parameter_type: type[DecompressionParameter]) -> None: ...
93+
def train_dict(samples_bytes: bytes, samples_sizes: tuple[int, ...], dict_size: int, /) -> bytes: ...
94+
95+
zstd_version: Final[str]
96+
zstd_version_number: Final[int]

mypy/typeshed/stdlib/asyncio/tasks.pyi

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,25 @@ if sys.version_info >= (3, 12):
423423
else:
424424
def current_task(loop: AbstractEventLoop | None = None) -> Task[Any] | None: ...
425425

426+
if sys.version_info >= (3, 14):
427+
def eager_task_factory(
428+
loop: AbstractEventLoop | None,
429+
coro: _TaskCompatibleCoro[_T_co],
430+
*,
431+
name: str | None = None,
432+
context: Context | None = None,
433+
eager_start: bool = True,
434+
) -> Task[_T_co]: ...
435+
436+
elif sys.version_info >= (3, 12):
437+
def eager_task_factory(
438+
loop: AbstractEventLoop | None,
439+
coro: _TaskCompatibleCoro[_T_co],
440+
*,
441+
name: str | None = None,
442+
context: Context | None = None,
443+
) -> Task[_T_co]: ...
444+
426445
if sys.version_info >= (3, 12):
427446
_TaskT_co = TypeVar("_TaskT_co", bound=Task[Any], covariant=True)
428447

@@ -451,10 +470,3 @@ if sys.version_info >= (3, 12):
451470
def create_eager_task_factory(
452471
custom_task_constructor: _CustomTaskConstructor[_TaskT_co],
453472
) -> _EagerTaskFactoryType[_TaskT_co]: ...
454-
def eager_task_factory(
455-
loop: AbstractEventLoop | None,
456-
coro: _TaskCompatibleCoro[_T_co],
457-
*,
458-
name: str | None = None,
459-
context: Context | None = None,
460-
) -> Task[_T_co]: ...

mypy/typeshed/stdlib/bz2.pyi

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import sys
22
from _bz2 import BZ2Compressor as BZ2Compressor, BZ2Decompressor as BZ2Decompressor
33
from _typeshed import ReadableBuffer, StrOrBytesPath, WriteableBuffer
44
from collections.abc import Iterable
5-
from typing import IO, Literal, Protocol, SupportsIndex, TextIO, overload
5+
from io import TextIOWrapper
6+
from typing import IO, Literal, Protocol, SupportsIndex, overload
67
from typing_extensions import Self, TypeAlias
78

89
if sys.version_info >= (3, 14):
@@ -48,7 +49,7 @@ def open(
4849
encoding: str | None = None,
4950
errors: str | None = None,
5051
newline: str | None = None,
51-
) -> TextIO: ...
52+
) -> TextIOWrapper: ...
5253
@overload
5354
def open(
5455
filename: _WritableFileobj,
@@ -66,7 +67,7 @@ def open(
6667
encoding: str | None = None,
6768
errors: str | None = None,
6869
newline: str | None = None,
69-
) -> TextIO: ...
70+
) -> TextIOWrapper: ...
7071
@overload
7172
def open(
7273
filename: StrOrBytesPath,
@@ -84,7 +85,7 @@ def open(
8485
encoding: str | None = None,
8586
errors: str | None = None,
8687
newline: str | None = None,
87-
) -> TextIO: ...
88+
) -> TextIOWrapper: ...
8889
@overload
8990
def open(
9091
filename: StrOrBytesPath | _ReadableFileobj | _WritableFileobj,
@@ -93,7 +94,7 @@ def open(
9394
encoding: str | None = None,
9495
errors: str | None = None,
9596
newline: str | None = None,
96-
) -> BZ2File | TextIO: ...
97+
) -> BZ2File | TextIOWrapper: ...
9798

9899
class BZ2File(BaseStream, IO[bytes]):
99100
def __enter__(self) -> Self: ...

mypy/typeshed/stdlib/compression/_common/_streams.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
from _typeshed import Incomplete, WriteableBuffer
22
from collections.abc import Callable
33
from io import DEFAULT_BUFFER_SIZE, BufferedIOBase, RawIOBase
4-
from typing import Any, Protocol
4+
from typing import Any, Protocol, type_check_only
55

66
BUFFER_SIZE = DEFAULT_BUFFER_SIZE
77

8+
@type_check_only
89
class _Reader(Protocol):
910
def read(self, n: int, /) -> bytes: ...
1011
def seekable(self) -> bool: ...
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import enum
2+
from _typeshed import ReadableBuffer
3+
from collections.abc import Iterable, Mapping
4+
from compression.zstd._zstdfile import ZstdFile, open
5+
from typing import Final, final
6+
7+
import _zstd
8+
from _zstd import ZstdCompressor, ZstdDecompressor, ZstdDict, ZstdError, get_frame_size, zstd_version
9+
10+
__all__ = (
11+
# compression.zstd
12+
"COMPRESSION_LEVEL_DEFAULT",
13+
"compress",
14+
"CompressionParameter",
15+
"decompress",
16+
"DecompressionParameter",
17+
"finalize_dict",
18+
"get_frame_info",
19+
"Strategy",
20+
"train_dict",
21+
# compression.zstd._zstdfile
22+
"open",
23+
"ZstdFile",
24+
# _zstd
25+
"get_frame_size",
26+
"zstd_version",
27+
"zstd_version_info",
28+
"ZstdCompressor",
29+
"ZstdDecompressor",
30+
"ZstdDict",
31+
"ZstdError",
32+
)
33+
34+
zstd_version_info: Final[tuple[int, int, int]]
35+
COMPRESSION_LEVEL_DEFAULT: Final = _zstd.ZSTD_CLEVEL_DEFAULT
36+
37+
class FrameInfo:
38+
decompressed_size: int
39+
dictionary_id: int
40+
def __init__(self, decompressed_size: int, dictionary_id: int) -> None: ...
41+
42+
def get_frame_info(frame_buffer: ReadableBuffer) -> FrameInfo: ...
43+
def train_dict(samples: Iterable[ReadableBuffer], dict_size: int) -> ZstdDict: ...
44+
def finalize_dict(zstd_dict: ZstdDict, /, samples: Iterable[ReadableBuffer], dict_size: int, level: int) -> ZstdDict: ...
45+
def compress(
46+
data: ReadableBuffer, level: int | None = None, options: Mapping[int, int] | None = None, zstd_dict: ZstdDict | None = None
47+
) -> bytes: ...
48+
def decompress(data: ReadableBuffer, zstd_dict: ZstdDict | None = None, options: Mapping[int, int] | None = None) -> bytes: ...
49+
@final
50+
class CompressionParameter(enum.IntEnum):
51+
compression_level = _zstd.ZSTD_c_compressionLevel
52+
window_log = _zstd.ZSTD_c_windowLog
53+
hash_log = _zstd.ZSTD_c_hashLog
54+
chain_log = _zstd.ZSTD_c_chainLog
55+
search_log = _zstd.ZSTD_c_searchLog
56+
min_match = _zstd.ZSTD_c_minMatch
57+
target_length = _zstd.ZSTD_c_targetLength
58+
strategy = _zstd.ZSTD_c_strategy
59+
enable_long_distance_matching = _zstd.ZSTD_c_enableLongDistanceMatching
60+
ldm_hash_log = _zstd.ZSTD_c_ldmHashLog
61+
ldm_min_match = _zstd.ZSTD_c_ldmMinMatch
62+
ldm_bucket_size_log = _zstd.ZSTD_c_ldmBucketSizeLog
63+
ldm_hash_rate_log = _zstd.ZSTD_c_ldmHashRateLog
64+
content_size_flag = _zstd.ZSTD_c_contentSizeFlag
65+
checksum_flag = _zstd.ZSTD_c_checksumFlag
66+
dict_id_flag = _zstd.ZSTD_c_dictIDFlag
67+
nb_workers = _zstd.ZSTD_c_nbWorkers
68+
job_size = _zstd.ZSTD_c_jobSize
69+
overlap_log = _zstd.ZSTD_c_overlapLog
70+
def bounds(self) -> tuple[int, int]: ...
71+
72+
@final
73+
class DecompressionParameter(enum.IntEnum):
74+
window_log_max = _zstd.ZSTD_d_windowLogMax
75+
def bounds(self) -> tuple[int, int]: ...
76+
77+
@final
78+
class Strategy(enum.IntEnum):
79+
fast = _zstd.ZSTD_fast
80+
dfast = _zstd.ZSTD_dfast
81+
greedy = _zstd.ZSTD_greedy
82+
lazy = _zstd.ZSTD_lazy
83+
lazy2 = _zstd.ZSTD_lazy2
84+
btlazy2 = _zstd.ZSTD_btlazy2
85+
btopt = _zstd.ZSTD_btopt
86+
btultra = _zstd.ZSTD_btultra
87+
btultra2 = _zstd.ZSTD_btultra2

0 commit comments

Comments
 (0)