Skip to content

Commit

Permalink
Sync typeshed (#18057)
Browse files Browse the repository at this point in the history
  • Loading branch information
onlined authored Oct 27, 2024
1 parent 2d785df commit 80843fe
Show file tree
Hide file tree
Showing 27 changed files with 309 additions and 146 deletions.
1 change: 1 addition & 0 deletions mypy/typeshed/stdlib/VERSIONS
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ __main__: 3.0-
_ast: 3.0-
_asyncio: 3.0-
_bisect: 3.0-
_blake2: 3.6-
_bootlocale: 3.4-3.9
_codecs: 3.0-
_collections_abc: 3.3-
Expand Down
117 changes: 117 additions & 0 deletions mypy/typeshed/stdlib/_blake2.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import sys
from _typeshed import ReadableBuffer
from typing import ClassVar, final
from typing_extensions import Self

BLAKE2B_MAX_DIGEST_SIZE: int = 64
BLAKE2B_MAX_KEY_SIZE: int = 64
BLAKE2B_PERSON_SIZE: int = 16
BLAKE2B_SALT_SIZE: int = 16
BLAKE2S_MAX_DIGEST_SIZE: int = 32
BLAKE2S_MAX_KEY_SIZE: int = 32
BLAKE2S_PERSON_SIZE: int = 8
BLAKE2S_SALT_SIZE: int = 8

@final
class blake2b:
MAX_DIGEST_SIZE: ClassVar[int] = 64
MAX_KEY_SIZE: ClassVar[int] = 64
PERSON_SIZE: ClassVar[int] = 16
SALT_SIZE: ClassVar[int] = 16
block_size: int
digest_size: int
name: str
if sys.version_info >= (3, 9):
def __init__(
self,
data: ReadableBuffer = b"",
/,
*,
digest_size: int = 64,
key: ReadableBuffer = b"",
salt: ReadableBuffer = b"",
person: ReadableBuffer = b"",
fanout: int = 1,
depth: int = 1,
leaf_size: int = 0,
node_offset: int = 0,
node_depth: int = 0,
inner_size: int = 0,
last_node: bool = False,
usedforsecurity: bool = True,
) -> None: ...
else:
def __init__(
self,
data: ReadableBuffer = b"",
/,
*,
digest_size: int = 64,
key: ReadableBuffer = b"",
salt: ReadableBuffer = b"",
person: ReadableBuffer = b"",
fanout: int = 1,
depth: int = 1,
leaf_size: int = 0,
node_offset: int = 0,
node_depth: int = 0,
inner_size: int = 0,
last_node: bool = False,
) -> None: ...

def copy(self) -> Self: ...
def digest(self) -> bytes: ...
def hexdigest(self) -> str: ...
def update(self, data: ReadableBuffer, /) -> None: ...

@final
class blake2s:
MAX_DIGEST_SIZE: ClassVar[int] = 32
MAX_KEY_SIZE: ClassVar[int] = 32
PERSON_SIZE: ClassVar[int] = 8
SALT_SIZE: ClassVar[int] = 8
block_size: int
digest_size: int
name: str
if sys.version_info >= (3, 9):
def __init__(
self,
data: ReadableBuffer = b"",
/,
*,
digest_size: int = 32,
key: ReadableBuffer = b"",
salt: ReadableBuffer = b"",
person: ReadableBuffer = b"",
fanout: int = 1,
depth: int = 1,
leaf_size: int = 0,
node_offset: int = 0,
node_depth: int = 0,
inner_size: int = 0,
last_node: bool = False,
usedforsecurity: bool = True,
) -> None: ...
else:
def __init__(
self,
data: ReadableBuffer = b"",
/,
*,
digest_size: int = 32,
key: ReadableBuffer = b"",
salt: ReadableBuffer = b"",
person: ReadableBuffer = b"",
fanout: int = 1,
depth: int = 1,
leaf_size: int = 0,
node_offset: int = 0,
node_depth: int = 0,
inner_size: int = 0,
last_node: bool = False,
) -> None: ...

def copy(self) -> Self: ...
def digest(self) -> bytes: ...
def hexdigest(self) -> str: ...
def update(self, data: ReadableBuffer, /) -> None: ...
2 changes: 1 addition & 1 deletion mypy/typeshed/stdlib/_interpreters.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ _Configs: TypeAlias = Literal["default", "isolated", "legacy", "empty", ""]

class InterpreterError(Exception): ...
class InterpreterNotFoundError(InterpreterError): ...
class NotShareableError(Exception): ...
class NotShareableError(ValueError): ...

class CrossInterpreterBufferView:
def __buffer__(self, flags: int, /) -> memoryview: ...
Expand Down
21 changes: 15 additions & 6 deletions mypy/typeshed/stdlib/_io.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,24 @@ class BytesIO(BufferedIOBase, _BufferedIOBase, BinaryIO): # type: ignore[misc]

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

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

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

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

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

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

class IncrementalNewlineDecoder(codecs.IncrementalDecoder):
class IncrementalNewlineDecoder:
def __init__(self, decoder: codecs.IncrementalDecoder | None, translate: bool, errors: str = ...) -> None: ...
def decode(self, input: ReadableBuffer | str, final: bool = False) -> str: ...
@property
def newlines(self) -> str | tuple[str, ...] | None: ...
def getstate(self) -> tuple[bytes, int]: ...
def reset(self) -> None: ...
def setstate(self, state: tuple[bytes, int], /) -> None: ...

if sys.version_info >= (3, 10):
Expand Down
17 changes: 12 additions & 5 deletions mypy/typeshed/stdlib/ast.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2023,11 +2023,18 @@ class NodeVisitor:
def visit_AugLoad(self, node: AugLoad) -> Any: ...
def visit_AugStore(self, node: AugStore) -> Any: ...
def visit_Param(self, node: Param) -> Any: ...
def visit_Num(self, node: Num) -> Any: ...
def visit_Str(self, node: Str) -> Any: ...
def visit_Bytes(self, node: Bytes) -> Any: ...
def visit_NameConstant(self, node: NameConstant) -> Any: ...
def visit_Ellipsis(self, node: Ellipsis) -> Any: ...

if sys.version_info < (3, 14):
@deprecated("Replaced by visit_Constant; removed in Python 3.14")
def visit_Num(self, node: Num) -> Any: ... # type: ignore[deprecated]
@deprecated("Replaced by visit_Constant; removed in Python 3.14")
def visit_Str(self, node: Str) -> Any: ... # type: ignore[deprecated]
@deprecated("Replaced by visit_Constant; removed in Python 3.14")
def visit_Bytes(self, node: Bytes) -> Any: ... # type: ignore[deprecated]
@deprecated("Replaced by visit_Constant; removed in Python 3.14")
def visit_NameConstant(self, node: NameConstant) -> Any: ... # type: ignore[deprecated]
@deprecated("Replaced by visit_Constant; removed in Python 3.14")
def visit_Ellipsis(self, node: Ellipsis) -> Any: ... # type: ignore[deprecated]

class NodeTransformer(NodeVisitor):
def generic_visit(self, node: AST) -> AST: ...
Expand Down
9 changes: 7 additions & 2 deletions mypy/typeshed/stdlib/asyncio/tasks.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ from _asyncio import (
_register_task as _register_task,
_unregister_task as _unregister_task,
)
from collections.abc import Awaitable, Coroutine, Generator, Iterable, Iterator
from collections.abc import AsyncIterator, Awaitable, Coroutine, Generator, Iterable, Iterator
from typing import Any, Literal, Protocol, TypeVar, overload
from typing_extensions import TypeAlias

Expand Down Expand Up @@ -84,7 +84,12 @@ FIRST_COMPLETED = concurrent.futures.FIRST_COMPLETED
FIRST_EXCEPTION = concurrent.futures.FIRST_EXCEPTION
ALL_COMPLETED = concurrent.futures.ALL_COMPLETED

if sys.version_info >= (3, 10):
if sys.version_info >= (3, 13):
class _SyncAndAsyncIterator(Iterator[_T_co], AsyncIterator[_T_co], Protocol[_T_co]): ...

def as_completed(fs: Iterable[_FutureLike[_T]], *, timeout: float | None = None) -> _SyncAndAsyncIterator[Future[_T]]: ...

elif sys.version_info >= (3, 10):
def as_completed(fs: Iterable[_FutureLike[_T]], *, timeout: float | None = None) -> Iterator[Future[_T]]: ...

else:
Expand Down
37 changes: 25 additions & 12 deletions mypy/typeshed/stdlib/builtins.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ from _typeshed import (
ConvertibleToFloat,
ConvertibleToInt,
FileDescriptorOrPath,
MaybeNone,
OpenBinaryMode,
OpenBinaryModeReading,
OpenBinaryModeUpdating,
Expand Down Expand Up @@ -93,6 +94,9 @@ _SupportsAnextT = TypeVar("_SupportsAnextT", bound=SupportsAnext[Any], covariant
_AwaitableT = TypeVar("_AwaitableT", bound=Awaitable[Any])
_AwaitableT_co = TypeVar("_AwaitableT_co", bound=Awaitable[Any], covariant=True)
_P = ParamSpec("_P")
_StartT = TypeVar("_StartT", covariant=True, default=Any)
_StopT = TypeVar("_StopT", covariant=True, default=Any)
_StepT = TypeVar("_StepT", covariant=True, default=Any)

class object:
__doc__: str | None
Expand Down Expand Up @@ -786,7 +790,7 @@ class memoryview(Sequence[_I]):
@overload
def __setitem__(self, key: slice, value: ReadableBuffer, /) -> None: ...
@overload
def __setitem__(self, key: SupportsIndex | tuple[SupportsIndex, ...], value: SupportsIndex, /) -> None: ...
def __setitem__(self, key: SupportsIndex | tuple[SupportsIndex, ...], value: _I, /) -> None: ...
if sys.version_info >= (3, 10):
def tobytes(self, order: Literal["C", "F", "A"] | None = "C") -> bytes: ...
else:
Expand Down Expand Up @@ -838,22 +842,31 @@ class bool(int):
def __invert__(self) -> int: ...

@final
class slice:
class slice(Generic[_StartT, _StopT, _StepT]):
@property
def start(self) -> Any: ...
def start(self) -> _StartT: ...
@property
def step(self) -> Any: ...
def step(self) -> _StepT: ...
@property
def stop(self) -> Any: ...
def stop(self) -> _StopT: ...
@overload
def __new__(cls, stop: Any, /) -> Self: ...
def __new__(cls, stop: int | None, /) -> slice[int | MaybeNone, int | MaybeNone, int | MaybeNone]: ...
@overload
def __new__(cls, start: Any, stop: Any, step: Any = ..., /) -> Self: ...
def __new__(
cls, start: int | None, stop: int | None, step: int | None = None, /
) -> slice[int | MaybeNone, int | MaybeNone, int | MaybeNone]: ...
@overload
def __new__(cls, stop: _T2, /) -> slice[Any, _T2, Any]: ...
@overload
def __new__(cls, start: _T1, stop: _T2, /) -> slice[_T1, _T2, Any]: ...
@overload
def __new__(cls, start: _T1, stop: _T2, step: _T3, /) -> slice[_T1, _T2, _T3]: ...
def __eq__(self, value: object, /) -> bool: ...
if sys.version_info >= (3, 12):
def __hash__(self) -> int: ...
else:
__hash__: ClassVar[None] # type: ignore[assignment]

def indices(self, len: SupportsIndex, /) -> tuple[int, int, int]: ...

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

class enumerate(Iterator[tuple[int, _T]]):
class enumerate(Generic[_T]):
def __new__(cls, iterable: Iterable[_T], start: int = 0) -> Self: ...
def __iter__(self) -> Self: ...
def __next__(self) -> tuple[int, _T]: ...
Expand Down Expand Up @@ -1311,7 +1324,7 @@ else:

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

class filter(Iterator[_T]):
class filter(Generic[_T]):
@overload
def __new__(cls, function: None, iterable: Iterable[_T | None], /) -> Self: ...
@overload
Expand Down Expand Up @@ -1372,7 +1385,7 @@ def len(obj: Sized, /) -> int: ...
def license() -> None: ...
def locals() -> dict[str, Any]: ...

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

class reversed(Iterator[_T]):
class reversed(Generic[_T]):
@overload
def __new__(cls, sequence: Reversible[_T], /) -> Iterator[_T]: ... # type: ignore[misc]
@overload
Expand Down Expand Up @@ -1675,7 +1688,7 @@ def vars(object: type, /) -> types.MappingProxyType[str, Any]: ...
@overload
def vars(object: Any = ..., /) -> dict[str, Any]: ...

class zip(Iterator[_T_co]):
class zip(Generic[_T_co]):
if sys.version_info >= (3, 10):
@overload
def __new__(cls, *, strict: bool = ...) -> zip[Any]: ...
Expand Down
14 changes: 9 additions & 5 deletions mypy/typeshed/stdlib/contextlib.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,11 @@ class ContextDecorator:
def _recreate_cm(self) -> Self: ...
def __call__(self, func: _F) -> _F: ...

class _GeneratorContextManager(AbstractContextManager[_T_co, bool | None], ContextDecorator):
class _GeneratorContextManagerBase: ...

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

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

else:
class _AsyncGeneratorContextManager(AbstractAsyncContextManager[_T_co, bool | None]):
class _AsyncGeneratorContextManager(_GeneratorContextManagerBase, AbstractAsyncContextManager[_T_co, bool | None]):
def __init__(self, func: Callable[..., AsyncIterator[_T_co]], args: tuple[Any, ...], kwds: dict[str, Any]) -> None: ...
gen: AsyncGenerator[_T_co, Any]
func: Callable[..., AsyncGenerator[_T_co, Any]]
Expand Down
13 changes: 13 additions & 0 deletions mypy/typeshed/stdlib/distutils/_msvccompiler.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from _typeshed import Incomplete
from distutils.ccompiler import CCompiler
from typing import ClassVar, Final

PLAT_SPEC_TO_RUNTIME: Final[dict[str, str]]
PLAT_TO_VCVARS: Final[dict[str, str]]

class MSVCCompiler(CCompiler):
compiler_type: ClassVar[str]
executables: ClassVar[dict[Incomplete, Incomplete]]
res_extension: ClassVar[str]
initialized: bool
def initialize(self, plat_name: str | None = None) -> None: ...
Loading

0 comments on commit 80843fe

Please sign in to comment.