Skip to content

Commit 80843fe

Browse files
authored
Sync typeshed (#18057)
Source commit: python/typeshed@61ba4de
1 parent 2d785df commit 80843fe

27 files changed

+309
-146
lines changed

mypy/typeshed/stdlib/VERSIONS

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ __main__: 3.0-
2222
_ast: 3.0-
2323
_asyncio: 3.0-
2424
_bisect: 3.0-
25+
_blake2: 3.6-
2526
_bootlocale: 3.4-3.9
2627
_codecs: 3.0-
2728
_collections_abc: 3.3-

mypy/typeshed/stdlib/_blake2.pyi

+117
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
import sys
2+
from _typeshed import ReadableBuffer
3+
from typing import ClassVar, final
4+
from typing_extensions import Self
5+
6+
BLAKE2B_MAX_DIGEST_SIZE: int = 64
7+
BLAKE2B_MAX_KEY_SIZE: int = 64
8+
BLAKE2B_PERSON_SIZE: int = 16
9+
BLAKE2B_SALT_SIZE: int = 16
10+
BLAKE2S_MAX_DIGEST_SIZE: int = 32
11+
BLAKE2S_MAX_KEY_SIZE: int = 32
12+
BLAKE2S_PERSON_SIZE: int = 8
13+
BLAKE2S_SALT_SIZE: int = 8
14+
15+
@final
16+
class blake2b:
17+
MAX_DIGEST_SIZE: ClassVar[int] = 64
18+
MAX_KEY_SIZE: ClassVar[int] = 64
19+
PERSON_SIZE: ClassVar[int] = 16
20+
SALT_SIZE: ClassVar[int] = 16
21+
block_size: int
22+
digest_size: int
23+
name: str
24+
if sys.version_info >= (3, 9):
25+
def __init__(
26+
self,
27+
data: ReadableBuffer = b"",
28+
/,
29+
*,
30+
digest_size: int = 64,
31+
key: ReadableBuffer = b"",
32+
salt: ReadableBuffer = b"",
33+
person: ReadableBuffer = b"",
34+
fanout: int = 1,
35+
depth: int = 1,
36+
leaf_size: int = 0,
37+
node_offset: int = 0,
38+
node_depth: int = 0,
39+
inner_size: int = 0,
40+
last_node: bool = False,
41+
usedforsecurity: bool = True,
42+
) -> None: ...
43+
else:
44+
def __init__(
45+
self,
46+
data: ReadableBuffer = b"",
47+
/,
48+
*,
49+
digest_size: int = 64,
50+
key: ReadableBuffer = b"",
51+
salt: ReadableBuffer = b"",
52+
person: ReadableBuffer = b"",
53+
fanout: int = 1,
54+
depth: int = 1,
55+
leaf_size: int = 0,
56+
node_offset: int = 0,
57+
node_depth: int = 0,
58+
inner_size: int = 0,
59+
last_node: bool = False,
60+
) -> None: ...
61+
62+
def copy(self) -> Self: ...
63+
def digest(self) -> bytes: ...
64+
def hexdigest(self) -> str: ...
65+
def update(self, data: ReadableBuffer, /) -> None: ...
66+
67+
@final
68+
class blake2s:
69+
MAX_DIGEST_SIZE: ClassVar[int] = 32
70+
MAX_KEY_SIZE: ClassVar[int] = 32
71+
PERSON_SIZE: ClassVar[int] = 8
72+
SALT_SIZE: ClassVar[int] = 8
73+
block_size: int
74+
digest_size: int
75+
name: str
76+
if sys.version_info >= (3, 9):
77+
def __init__(
78+
self,
79+
data: ReadableBuffer = b"",
80+
/,
81+
*,
82+
digest_size: int = 32,
83+
key: ReadableBuffer = b"",
84+
salt: ReadableBuffer = b"",
85+
person: ReadableBuffer = b"",
86+
fanout: int = 1,
87+
depth: int = 1,
88+
leaf_size: int = 0,
89+
node_offset: int = 0,
90+
node_depth: int = 0,
91+
inner_size: int = 0,
92+
last_node: bool = False,
93+
usedforsecurity: bool = True,
94+
) -> None: ...
95+
else:
96+
def __init__(
97+
self,
98+
data: ReadableBuffer = b"",
99+
/,
100+
*,
101+
digest_size: int = 32,
102+
key: ReadableBuffer = b"",
103+
salt: ReadableBuffer = b"",
104+
person: ReadableBuffer = b"",
105+
fanout: int = 1,
106+
depth: int = 1,
107+
leaf_size: int = 0,
108+
node_offset: int = 0,
109+
node_depth: int = 0,
110+
inner_size: int = 0,
111+
last_node: bool = False,
112+
) -> None: ...
113+
114+
def copy(self) -> Self: ...
115+
def digest(self) -> bytes: ...
116+
def hexdigest(self) -> str: ...
117+
def update(self, data: ReadableBuffer, /) -> None: ...

mypy/typeshed/stdlib/_interpreters.pyi

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ _Configs: TypeAlias = Literal["default", "isolated", "legacy", "empty", ""]
77

88
class InterpreterError(Exception): ...
99
class InterpreterNotFoundError(InterpreterError): ...
10-
class NotShareableError(Exception): ...
10+
class NotShareableError(ValueError): ...
1111

1212
class CrossInterpreterBufferView:
1313
def __buffer__(self, flags: int, /) -> memoryview: ...

mypy/typeshed/stdlib/_io.pyi

+15-6
Original file line numberDiff line numberDiff line change
@@ -86,19 +86,24 @@ class BytesIO(BufferedIOBase, _BufferedIOBase, BinaryIO): # type: ignore[misc]
8686

8787
class BufferedReader(BufferedIOBase, _BufferedIOBase, BinaryIO): # type: ignore[misc] # incompatible definitions of methods in the base classes
8888
raw: RawIOBase
89-
def __init__(self, raw: RawIOBase, buffer_size: int = ...) -> None: ...
89+
def __init__(self, raw: RawIOBase, buffer_size: int = 8192) -> None: ...
9090
def peek(self, size: int = 0, /) -> bytes: ...
9191

9292
class BufferedWriter(BufferedIOBase, _BufferedIOBase, BinaryIO): # type: ignore[misc] # incompatible definitions of writelines in the base classes
9393
raw: RawIOBase
94-
def __init__(self, raw: RawIOBase, buffer_size: int = ...) -> None: ...
94+
def __init__(self, raw: RawIOBase, buffer_size: int = 8192) -> None: ...
9595
def write(self, buffer: ReadableBuffer, /) -> int: ...
9696

97-
class BufferedRandom(BufferedReader, BufferedWriter, BufferedIOBase, _BufferedIOBase): # type: ignore[misc] # incompatible definitions of methods in the base classes
97+
class BufferedRandom(BufferedIOBase, _BufferedIOBase, BinaryIO): # type: ignore[misc] # incompatible definitions of methods in the base classes
98+
mode: str
99+
name: Any
100+
raw: RawIOBase
101+
def __init__(self, raw: RawIOBase, buffer_size: int = 8192) -> None: ...
98102
def seek(self, target: int, whence: int = 0, /) -> int: ... # stubtest needs this
103+
def peek(self, size: int = 0, /) -> bytes: ...
99104

100105
class BufferedRWPair(BufferedIOBase, _BufferedIOBase):
101-
def __init__(self, reader: RawIOBase, writer: RawIOBase, buffer_size: int = ...) -> None: ...
106+
def __init__(self, reader: RawIOBase, writer: RawIOBase, buffer_size: int = 8192) -> None: ...
102107
def peek(self, size: int = ..., /) -> bytes: ...
103108

104109
class _TextIOBase(_IOBase):
@@ -173,19 +178,23 @@ class TextIOWrapper(TextIOBase, _TextIOBase, TextIO, Generic[_BufferT_co]): # t
173178
# operations.
174179
def seek(self, cookie: int, whence: int = 0, /) -> int: ...
175180

176-
class StringIO(TextIOWrapper, TextIOBase, _TextIOBase): # type: ignore[misc] # incompatible definitions of write in the base classes
181+
class StringIO(TextIOBase, _TextIOBase, TextIO): # type: ignore[misc] # incompatible definitions of write in the base classes
177182
def __init__(self, initial_value: str | None = ..., newline: str | None = ...) -> None: ...
178183
# StringIO does not contain a "name" field. This workaround is necessary
179184
# to allow StringIO sub-classes to add this field, as it is defined
180185
# as a read-only property on IO[].
181186
name: Any
182187
def getvalue(self) -> str: ...
188+
@property
189+
def line_buffering(self) -> bool: ...
183190

184-
class IncrementalNewlineDecoder(codecs.IncrementalDecoder):
191+
class IncrementalNewlineDecoder:
185192
def __init__(self, decoder: codecs.IncrementalDecoder | None, translate: bool, errors: str = ...) -> None: ...
186193
def decode(self, input: ReadableBuffer | str, final: bool = False) -> str: ...
187194
@property
188195
def newlines(self) -> str | tuple[str, ...] | None: ...
196+
def getstate(self) -> tuple[bytes, int]: ...
197+
def reset(self) -> None: ...
189198
def setstate(self, state: tuple[bytes, int], /) -> None: ...
190199

191200
if sys.version_info >= (3, 10):

mypy/typeshed/stdlib/ast.pyi

+12-5
Original file line numberDiff line numberDiff line change
@@ -2023,11 +2023,18 @@ class NodeVisitor:
20232023
def visit_AugLoad(self, node: AugLoad) -> Any: ...
20242024
def visit_AugStore(self, node: AugStore) -> Any: ...
20252025
def visit_Param(self, node: Param) -> Any: ...
2026-
def visit_Num(self, node: Num) -> Any: ...
2027-
def visit_Str(self, node: Str) -> Any: ...
2028-
def visit_Bytes(self, node: Bytes) -> Any: ...
2029-
def visit_NameConstant(self, node: NameConstant) -> Any: ...
2030-
def visit_Ellipsis(self, node: Ellipsis) -> Any: ...
2026+
2027+
if sys.version_info < (3, 14):
2028+
@deprecated("Replaced by visit_Constant; removed in Python 3.14")
2029+
def visit_Num(self, node: Num) -> Any: ... # type: ignore[deprecated]
2030+
@deprecated("Replaced by visit_Constant; removed in Python 3.14")
2031+
def visit_Str(self, node: Str) -> Any: ... # type: ignore[deprecated]
2032+
@deprecated("Replaced by visit_Constant; removed in Python 3.14")
2033+
def visit_Bytes(self, node: Bytes) -> Any: ... # type: ignore[deprecated]
2034+
@deprecated("Replaced by visit_Constant; removed in Python 3.14")
2035+
def visit_NameConstant(self, node: NameConstant) -> Any: ... # type: ignore[deprecated]
2036+
@deprecated("Replaced by visit_Constant; removed in Python 3.14")
2037+
def visit_Ellipsis(self, node: Ellipsis) -> Any: ... # type: ignore[deprecated]
20312038

20322039
class NodeTransformer(NodeVisitor):
20332040
def generic_visit(self, node: AST) -> AST: ...

mypy/typeshed/stdlib/asyncio/tasks.pyi

+7-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ from _asyncio import (
77
_register_task as _register_task,
88
_unregister_task as _unregister_task,
99
)
10-
from collections.abc import Awaitable, Coroutine, Generator, Iterable, Iterator
10+
from collections.abc import AsyncIterator, Awaitable, Coroutine, Generator, Iterable, Iterator
1111
from typing import Any, Literal, Protocol, TypeVar, overload
1212
from typing_extensions import TypeAlias
1313

@@ -84,7 +84,12 @@ FIRST_COMPLETED = concurrent.futures.FIRST_COMPLETED
8484
FIRST_EXCEPTION = concurrent.futures.FIRST_EXCEPTION
8585
ALL_COMPLETED = concurrent.futures.ALL_COMPLETED
8686

87-
if sys.version_info >= (3, 10):
87+
if sys.version_info >= (3, 13):
88+
class _SyncAndAsyncIterator(Iterator[_T_co], AsyncIterator[_T_co], Protocol[_T_co]): ...
89+
90+
def as_completed(fs: Iterable[_FutureLike[_T]], *, timeout: float | None = None) -> _SyncAndAsyncIterator[Future[_T]]: ...
91+
92+
elif sys.version_info >= (3, 10):
8893
def as_completed(fs: Iterable[_FutureLike[_T]], *, timeout: float | None = None) -> Iterator[Future[_T]]: ...
8994

9095
else:

mypy/typeshed/stdlib/builtins.pyi

+25-12
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ from _typeshed import (
99
ConvertibleToFloat,
1010
ConvertibleToInt,
1111
FileDescriptorOrPath,
12+
MaybeNone,
1213
OpenBinaryMode,
1314
OpenBinaryModeReading,
1415
OpenBinaryModeUpdating,
@@ -93,6 +94,9 @@ _SupportsAnextT = TypeVar("_SupportsAnextT", bound=SupportsAnext[Any], covariant
9394
_AwaitableT = TypeVar("_AwaitableT", bound=Awaitable[Any])
9495
_AwaitableT_co = TypeVar("_AwaitableT_co", bound=Awaitable[Any], covariant=True)
9596
_P = ParamSpec("_P")
97+
_StartT = TypeVar("_StartT", covariant=True, default=Any)
98+
_StopT = TypeVar("_StopT", covariant=True, default=Any)
99+
_StepT = TypeVar("_StepT", covariant=True, default=Any)
96100

97101
class object:
98102
__doc__: str | None
@@ -786,7 +790,7 @@ class memoryview(Sequence[_I]):
786790
@overload
787791
def __setitem__(self, key: slice, value: ReadableBuffer, /) -> None: ...
788792
@overload
789-
def __setitem__(self, key: SupportsIndex | tuple[SupportsIndex, ...], value: SupportsIndex, /) -> None: ...
793+
def __setitem__(self, key: SupportsIndex | tuple[SupportsIndex, ...], value: _I, /) -> None: ...
790794
if sys.version_info >= (3, 10):
791795
def tobytes(self, order: Literal["C", "F", "A"] | None = "C") -> bytes: ...
792796
else:
@@ -838,22 +842,31 @@ class bool(int):
838842
def __invert__(self) -> int: ...
839843

840844
@final
841-
class slice:
845+
class slice(Generic[_StartT, _StopT, _StepT]):
842846
@property
843-
def start(self) -> Any: ...
847+
def start(self) -> _StartT: ...
844848
@property
845-
def step(self) -> Any: ...
849+
def step(self) -> _StepT: ...
846850
@property
847-
def stop(self) -> Any: ...
851+
def stop(self) -> _StopT: ...
848852
@overload
849-
def __new__(cls, stop: Any, /) -> Self: ...
853+
def __new__(cls, stop: int | None, /) -> slice[int | MaybeNone, int | MaybeNone, int | MaybeNone]: ...
850854
@overload
851-
def __new__(cls, start: Any, stop: Any, step: Any = ..., /) -> Self: ...
855+
def __new__(
856+
cls, start: int | None, stop: int | None, step: int | None = None, /
857+
) -> slice[int | MaybeNone, int | MaybeNone, int | MaybeNone]: ...
858+
@overload
859+
def __new__(cls, stop: _T2, /) -> slice[Any, _T2, Any]: ...
860+
@overload
861+
def __new__(cls, start: _T1, stop: _T2, /) -> slice[_T1, _T2, Any]: ...
862+
@overload
863+
def __new__(cls, start: _T1, stop: _T2, step: _T3, /) -> slice[_T1, _T2, _T3]: ...
852864
def __eq__(self, value: object, /) -> bool: ...
853865
if sys.version_info >= (3, 12):
854866
def __hash__(self) -> int: ...
855867
else:
856868
__hash__: ClassVar[None] # type: ignore[assignment]
869+
857870
def indices(self, len: SupportsIndex, /) -> tuple[int, int, int]: ...
858871

859872
class tuple(Sequence[_T_co]):
@@ -1117,7 +1130,7 @@ class frozenset(AbstractSet[_T_co]):
11171130
if sys.version_info >= (3, 9):
11181131
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
11191132

1120-
class enumerate(Iterator[tuple[int, _T]]):
1133+
class enumerate(Generic[_T]):
11211134
def __new__(cls, iterable: Iterable[_T], start: int = 0) -> Self: ...
11221135
def __iter__(self) -> Self: ...
11231136
def __next__(self) -> tuple[int, _T]: ...
@@ -1311,7 +1324,7 @@ else:
13111324

13121325
def exit(code: sys._ExitCode = None) -> NoReturn: ...
13131326

1314-
class filter(Iterator[_T]):
1327+
class filter(Generic[_T]):
13151328
@overload
13161329
def __new__(cls, function: None, iterable: Iterable[_T | None], /) -> Self: ...
13171330
@overload
@@ -1372,7 +1385,7 @@ def len(obj: Sized, /) -> int: ...
13721385
def license() -> None: ...
13731386
def locals() -> dict[str, Any]: ...
13741387

1375-
class map(Iterator[_S]):
1388+
class map(Generic[_S]):
13761389
@overload
13771390
def __new__(cls, func: Callable[[_T1], _S], iter1: Iterable[_T1], /) -> Self: ...
13781391
@overload
@@ -1614,7 +1627,7 @@ def pow(base: _SupportsSomeKindOfPow, exp: float, mod: None = None) -> Any: ...
16141627
def pow(base: _SupportsSomeKindOfPow, exp: complex, mod: None = None) -> complex: ...
16151628
def quit(code: sys._ExitCode = None) -> NoReturn: ...
16161629

1617-
class reversed(Iterator[_T]):
1630+
class reversed(Generic[_T]):
16181631
@overload
16191632
def __new__(cls, sequence: Reversible[_T], /) -> Iterator[_T]: ... # type: ignore[misc]
16201633
@overload
@@ -1675,7 +1688,7 @@ def vars(object: type, /) -> types.MappingProxyType[str, Any]: ...
16751688
@overload
16761689
def vars(object: Any = ..., /) -> dict[str, Any]: ...
16771690

1678-
class zip(Iterator[_T_co]):
1691+
class zip(Generic[_T_co]):
16791692
if sys.version_info >= (3, 10):
16801693
@overload
16811694
def __new__(cls, *, strict: bool = ...) -> zip[Any]: ...

mypy/typeshed/stdlib/contextlib.pyi

+9-5
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,11 @@ class ContextDecorator:
5858
def _recreate_cm(self) -> Self: ...
5959
def __call__(self, func: _F) -> _F: ...
6060

61-
class _GeneratorContextManager(AbstractContextManager[_T_co, bool | None], ContextDecorator):
61+
class _GeneratorContextManagerBase: ...
62+
63+
class _GeneratorContextManager(_GeneratorContextManagerBase, AbstractContextManager[_T_co, bool | None], ContextDecorator):
6264
# __init__ and all instance attributes are actually inherited from _GeneratorContextManagerBase
63-
# _GeneratorContextManagerBase is more trouble than it's worth to include in the stub; see #6676
65+
# adding them there is more trouble than it's worth to include in the stub; see #6676
6466
def __init__(self, func: Callable[..., Iterator[_T_co]], args: tuple[Any, ...], kwds: dict[str, Any]) -> None: ...
6567
gen: Generator[_T_co, Any, Any]
6668
func: Callable[..., Generator[_T_co, Any, Any]]
@@ -84,9 +86,11 @@ if sys.version_info >= (3, 10):
8486
def _recreate_cm(self) -> Self: ...
8587
def __call__(self, func: _AF) -> _AF: ...
8688

87-
class _AsyncGeneratorContextManager(AbstractAsyncContextManager[_T_co, bool | None], AsyncContextDecorator):
89+
class _AsyncGeneratorContextManager(
90+
_GeneratorContextManagerBase, AbstractAsyncContextManager[_T_co, bool | None], AsyncContextDecorator
91+
):
8892
# __init__ and these attributes are actually defined in the base class _GeneratorContextManagerBase,
89-
# which is more trouble than it's worth to include in the stub (see #6676)
93+
# adding them there is more trouble than it's worth to include in the stub (see #6676)
9094
def __init__(self, func: Callable[..., AsyncIterator[_T_co]], args: tuple[Any, ...], kwds: dict[str, Any]) -> None: ...
9195
gen: AsyncGenerator[_T_co, Any]
9296
func: Callable[..., AsyncGenerator[_T_co, Any]]
@@ -97,7 +101,7 @@ if sys.version_info >= (3, 10):
97101
) -> bool | None: ...
98102

99103
else:
100-
class _AsyncGeneratorContextManager(AbstractAsyncContextManager[_T_co, bool | None]):
104+
class _AsyncGeneratorContextManager(_GeneratorContextManagerBase, AbstractAsyncContextManager[_T_co, bool | None]):
101105
def __init__(self, func: Callable[..., AsyncIterator[_T_co]], args: tuple[Any, ...], kwds: dict[str, Any]) -> None: ...
102106
gen: AsyncGenerator[_T_co, Any]
103107
func: Callable[..., AsyncGenerator[_T_co, Any]]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from _typeshed import Incomplete
2+
from distutils.ccompiler import CCompiler
3+
from typing import ClassVar, Final
4+
5+
PLAT_SPEC_TO_RUNTIME: Final[dict[str, str]]
6+
PLAT_TO_VCVARS: Final[dict[str, str]]
7+
8+
class MSVCCompiler(CCompiler):
9+
compiler_type: ClassVar[str]
10+
executables: ClassVar[dict[Incomplete, Incomplete]]
11+
res_extension: ClassVar[str]
12+
initialized: bool
13+
def initialize(self, plat_name: str | None = None) -> None: ...

0 commit comments

Comments
 (0)