Skip to content

Sync typeshed #11303

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 1 commit into from
Oct 10, 2021
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
10 changes: 8 additions & 2 deletions mypy/typeshed/stdlib/_typeshed/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# See the README.md file in this directory for more information.

import array
import ctypes
import mmap
import sys
from os import PathLike
Expand Down Expand Up @@ -167,8 +168,13 @@ class SupportsNoArgReadline(Protocol[_T_co]):
class SupportsWrite(Protocol[_T_contra]):
def write(self, __s: _T_contra) -> Any: ...

ReadableBuffer = Union[bytes, bytearray, memoryview, array.array[Any], mmap.mmap] # stable
WriteableBuffer = Union[bytearray, memoryview, array.array[Any], mmap.mmap] # stable
ReadOnlyBuffer = bytes # stable
# Anything that implements the read-write buffer interface.
# The buffer interface is defined purely on the C level, so we cannot define a normal Protocol
# for it. Instead we have to list the most common stdlib buffer classes in a Union.
WriteableBuffer = Union[bytearray, memoryview, array.array[Any], mmap.mmap, ctypes._CData] # stable
# Same as _WriteableBuffer, but also includes read-only buffer types (like bytes).
ReadableBuffer = Union[ReadOnlyBuffer, WriteableBuffer] # stable

# stable
if sys.version_info >= (3, 10):
Expand Down
103 changes: 73 additions & 30 deletions mypy/typeshed/stdlib/builtins.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -1325,36 +1325,79 @@ else:
def vars(__object: Any = ...) -> dict[str, Any]: ...

class zip(Iterator[_T_co], Generic[_T_co]):
@overload
def __new__(cls, __iter1: Iterable[_T1]) -> zip[Tuple[_T1]]: ...
@overload
def __new__(cls, __iter1: Iterable[_T1], __iter2: Iterable[_T2]) -> zip[Tuple[_T1, _T2]]: ...
@overload
def __new__(cls, __iter1: Iterable[_T1], __iter2: Iterable[_T2], __iter3: Iterable[_T3]) -> zip[Tuple[_T1, _T2, _T3]]: ...
@overload
def __new__(
cls, __iter1: Iterable[_T1], __iter2: Iterable[_T2], __iter3: Iterable[_T3], __iter4: Iterable[_T4]
) -> zip[Tuple[_T1, _T2, _T3, _T4]]: ...
@overload
def __new__(
cls,
__iter1: Iterable[_T1],
__iter2: Iterable[_T2],
__iter3: Iterable[_T3],
__iter4: Iterable[_T4],
__iter5: Iterable[_T5],
) -> zip[Tuple[_T1, _T2, _T3, _T4, _T5]]: ...
@overload
def __new__(
cls,
__iter1: Iterable[Any],
__iter2: Iterable[Any],
__iter3: Iterable[Any],
__iter4: Iterable[Any],
__iter5: Iterable[Any],
__iter6: Iterable[Any],
*iterables: Iterable[Any],
) -> zip[Tuple[Any, ...]]: ...
if sys.version_info >= (3, 10):
@overload
def __new__(cls, __iter1: Iterable[_T1], *, strict: bool = ...) -> zip[Tuple[_T1]]: ...
@overload
def __new__(cls, __iter1: Iterable[_T1], __iter2: Iterable[_T2], *, strict: bool = ...) -> zip[Tuple[_T1, _T2]]: ...
@overload
def __new__(
cls, __iter1: Iterable[_T1], __iter2: Iterable[_T2], __iter3: Iterable[_T3], *, strict: bool = ...
) -> zip[Tuple[_T1, _T2, _T3]]: ...
@overload
def __new__(
cls,
__iter1: Iterable[_T1],
__iter2: Iterable[_T2],
__iter3: Iterable[_T3],
__iter4: Iterable[_T4],
*,
strict: bool = ...,
) -> zip[Tuple[_T1, _T2, _T3, _T4]]: ...
@overload
def __new__(
cls,
__iter1: Iterable[_T1],
__iter2: Iterable[_T2],
__iter3: Iterable[_T3],
__iter4: Iterable[_T4],
__iter5: Iterable[_T5],
*,
strict: bool = ...,
) -> zip[Tuple[_T1, _T2, _T3, _T4, _T5]]: ...
@overload
def __new__(
cls,
__iter1: Iterable[Any],
__iter2: Iterable[Any],
__iter3: Iterable[Any],
__iter4: Iterable[Any],
__iter5: Iterable[Any],
__iter6: Iterable[Any],
*iterables: Iterable[Any],
strict: bool = ...,
) -> zip[Tuple[Any, ...]]: ...
else:
@overload
def __new__(cls, __iter1: Iterable[_T1]) -> zip[Tuple[_T1]]: ...
@overload
def __new__(cls, __iter1: Iterable[_T1], __iter2: Iterable[_T2]) -> zip[Tuple[_T1, _T2]]: ...
@overload
def __new__(cls, __iter1: Iterable[_T1], __iter2: Iterable[_T2], __iter3: Iterable[_T3]) -> zip[Tuple[_T1, _T2, _T3]]: ...
@overload
def __new__(
cls, __iter1: Iterable[_T1], __iter2: Iterable[_T2], __iter3: Iterable[_T3], __iter4: Iterable[_T4]
) -> zip[Tuple[_T1, _T2, _T3, _T4]]: ...
@overload
def __new__(
cls,
__iter1: Iterable[_T1],
__iter2: Iterable[_T2],
__iter3: Iterable[_T3],
__iter4: Iterable[_T4],
__iter5: Iterable[_T5],
) -> zip[Tuple[_T1, _T2, _T3, _T4, _T5]]: ...
@overload
def __new__(
cls,
__iter1: Iterable[Any],
__iter2: Iterable[Any],
__iter3: Iterable[Any],
__iter4: Iterable[Any],
__iter5: Iterable[Any],
__iter6: Iterable[Any],
*iterables: Iterable[Any],
) -> zip[Tuple[Any, ...]]: ...
def __iter__(self) -> Iterator[_T_co]: ...
def __next__(self) -> _T_co: ...

Expand Down
6 changes: 3 additions & 3 deletions mypy/typeshed/stdlib/collections/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,9 @@ class defaultdict(Dict[_KT, _VT], Generic[_KT, _VT]):
def copy(self: _S) -> _S: ...

class ChainMap(MutableMapping[_KT, _VT], Generic[_KT, _VT]):
maps: list[Mapping[_KT, _VT]]
def __init__(self, *maps: Mapping[_KT, _VT]) -> None: ...
def new_child(self: Self, m: Mapping[_KT, _VT] | None = ...) -> Self: ...
maps: list[MutableMapping[_KT, _VT]]
def __init__(self, *maps: MutableMapping[_KT, _VT]) -> None: ...
def new_child(self: Self, m: MutableMapping[_KT, _VT] | None = ...) -> Self: ...
@property
def parents(self: Self) -> Self: ...
def __setitem__(self, k: _KT, v: _VT) -> None: ...
Expand Down
6 changes: 3 additions & 3 deletions mypy/typeshed/stdlib/contextlib.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class ExitStack(ContextManager[ExitStack]):
def __init__(self) -> None: ...
def enter_context(self, cm: ContextManager[_T]) -> _T: ...
def push(self, exit: _CM_EF) -> _CM_EF: ...
def callback(self, callback: Callable[..., Any], *args: Any, **kwds: Any) -> Callable[..., Any]: ...
def callback(self, __callback: Callable[..., Any], *args: Any, **kwds: Any) -> Callable[..., Any]: ...
def pop_all(self: Self) -> Self: ...
def close(self) -> None: ...
def __enter__(self: Self) -> Self: ...
Expand All @@ -94,8 +94,8 @@ if sys.version_info >= (3, 7):
def enter_async_context(self, cm: AsyncContextManager[_T]) -> Awaitable[_T]: ...
def push(self, exit: _CM_EF) -> _CM_EF: ...
def push_async_exit(self, exit: _ACM_EF) -> _ACM_EF: ...
def callback(self, callback: Callable[..., Any], *args: Any, **kwds: Any) -> Callable[..., Any]: ...
def push_async_callback(self, callback: _CallbackCoroFunc, *args: Any, **kwds: Any) -> _CallbackCoroFunc: ...
def callback(self, __callback: Callable[..., Any], *args: Any, **kwds: Any) -> Callable[..., Any]: ...
def push_async_callback(self, __callback: _CallbackCoroFunc, *args: Any, **kwds: Any) -> _CallbackCoroFunc: ...
def pop_all(self: Self) -> Self: ...
def aclose(self) -> Awaitable[None]: ...
def __aenter__(self: Self) -> Awaitable[Self]: ...
Expand Down
13 changes: 3 additions & 10 deletions mypy/typeshed/stdlib/ctypes/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import sys
from array import array
from _typeshed import ReadableBuffer, WriteableBuffer
from typing import (
Any,
Callable,
Expand Down Expand Up @@ -72,13 +72,6 @@ if sys.platform == "win32":
pydll: LibraryLoader[PyDLL]
pythonapi: PyDLL

# Anything that implements the read-write buffer interface.
# The buffer interface is defined purely on the C level, so we cannot define a normal Protocol
# for it. Instead we have to list the most common stdlib buffer classes in a Union.
_WritableBuffer = _UnionT[bytearray, memoryview, array[Any], _CData]
# Same as _WritableBuffer, but also includes read-only buffer types (like bytes).
_ReadOnlyBuffer = _UnionT[_WritableBuffer, bytes]

class _CDataMeta(type):
# By default mypy complains about the following two methods, because strictly speaking cls
# might not be a Type[_CT]. However this can never actually happen, because the only class that
Expand All @@ -91,9 +84,9 @@ class _CData(metaclass=_CDataMeta):
_b_needsfree_: bool
_objects: Mapping[Any, int] | None
@classmethod
def from_buffer(cls: Type[_CT], source: _WritableBuffer, offset: int = ...) -> _CT: ...
def from_buffer(cls: Type[_CT], source: WriteableBuffer, offset: int = ...) -> _CT: ...
@classmethod
def from_buffer_copy(cls: Type[_CT], source: _ReadOnlyBuffer, offset: int = ...) -> _CT: ...
def from_buffer_copy(cls: Type[_CT], source: ReadableBuffer, offset: int = ...) -> _CT: ...
@classmethod
def from_address(cls: Type[_CT], address: int) -> _CT: ...
@classmethod
Expand Down
6 changes: 3 additions & 3 deletions mypy/typeshed/stdlib/enum.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ class IntFlag(int, Flag):
def __or__(self: _T, other: int | _T) -> _T: ...
def __and__(self: _T, other: int | _T) -> _T: ...
def __xor__(self: _T, other: int | _T) -> _T: ...
__ror__ = __or__
__rand__ = __and__
__rxor__ = __xor__
def __ror__(self: _T, n: int | _T) -> _T: ...
def __rand__(self: _T, n: int | _T) -> _T: ...
def __rxor__(self: _T, n: int | _T) -> _T: ...

if sys.version_info >= (3, 11):
class StrEnum(str, Enum):
Expand Down
15 changes: 5 additions & 10 deletions mypy/typeshed/stdlib/fcntl.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import sys
from _typeshed import FileDescriptorLike
from array import array
from typing import Any, Union, overload
from _typeshed import FileDescriptorLike, ReadOnlyBuffer, WriteableBuffer
from typing import Any, overload
from typing_extensions import Literal

FASYNC: int
Expand Down Expand Up @@ -85,17 +84,13 @@ LOCK_WRITE: int
def fcntl(__fd: FileDescriptorLike, __cmd: int, __arg: int = ...) -> int: ...
@overload
def fcntl(__fd: FileDescriptorLike, __cmd: int, __arg: bytes) -> bytes: ...

_ReadOnlyBuffer = bytes
_WritableBuffer = Union[bytearray, memoryview, array[Any]]

@overload
def ioctl(__fd: FileDescriptorLike, __request: int, __arg: int = ..., __mutate_flag: bool = ...) -> int: ...
@overload
def ioctl(__fd: FileDescriptorLike, __request: int, __arg: _WritableBuffer, __mutate_flag: Literal[True] = ...) -> int: ...
def ioctl(__fd: FileDescriptorLike, __request: int, __arg: WriteableBuffer, __mutate_flag: Literal[True] = ...) -> int: ...
@overload
def ioctl(__fd: FileDescriptorLike, __request: int, __arg: _WritableBuffer, __mutate_flag: Literal[False]) -> bytes: ...
def ioctl(__fd: FileDescriptorLike, __request: int, __arg: WriteableBuffer, __mutate_flag: Literal[False]) -> bytes: ...
@overload
def ioctl(__fd: FileDescriptorLike, __request: int, __arg: _ReadOnlyBuffer, __mutate_flag: bool = ...) -> bytes: ...
def ioctl(__fd: FileDescriptorLike, __request: int, __arg: ReadOnlyBuffer, __mutate_flag: bool = ...) -> bytes: ...
def flock(__fd: FileDescriptorLike, __operation: int) -> None: ...
def lockf(__fd: FileDescriptorLike, __cmd: int, __len: int = ..., __start: int = ..., __whence: int = ...) -> Any: ...
4 changes: 4 additions & 0 deletions mypy/typeshed/stdlib/importlib/machinery.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,7 @@ class ExtensionFileLoader(importlib.abc.ExecutionLoader):
def __init__(self, name: str, path: importlib.abc._Path) -> None: ...
def get_filename(self, name: str | None = ...) -> importlib.abc._Path: ...
def get_source(self, fullname: str) -> None: ...
def create_module(self, spec: ModuleSpec) -> types.ModuleType: ...
def exec_module(self, module: types.ModuleType) -> None: ...
def is_package(self, fullname: str) -> bool: ...
def get_code(self, fullname: str) -> None: ...
4 changes: 2 additions & 2 deletions mypy/typeshed/stdlib/inspect.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class Signature:
def __init__(
self, parameters: Sequence[Parameter] | None = ..., *, return_annotation: Any = ..., __validate_parameters__: bool = ...
) -> None: ...
empty: _empty
empty = _empty
@property
def parameters(self) -> types.MappingProxyType[str, Parameter]: ...
# TODO: can we be more specific here?
Expand Down Expand Up @@ -172,7 +172,7 @@ class _ParameterKind(enum.IntEnum):

class Parameter:
def __init__(self, name: str, kind: _ParameterKind, *, default: Any = ..., annotation: Any = ...) -> None: ...
empty: _empty
empty = _empty
name: str
default: Any
annotation: Any
Expand Down
4 changes: 2 additions & 2 deletions mypy/typeshed/stdlib/logging/handlers.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class BaseRotatingHandler(FileHandler):

class RotatingFileHandler(BaseRotatingHandler):
maxBytes: str # undocumented
backupCount: str # undocumented
backupCount: int # undocumented
if sys.version_info >= (3, 9):
def __init__(
self,
Expand All @@ -73,7 +73,7 @@ class RotatingFileHandler(BaseRotatingHandler):

class TimedRotatingFileHandler(BaseRotatingHandler):
when: str # undocumented
backupCount: str # undocumented
backupCount: int # undocumented
utc: bool # undocumented
atTime: datetime.datetime | None # undocumented
interval: int # undocumented
Expand Down
3 changes: 2 additions & 1 deletion mypy/typeshed/stdlib/multiprocessing/context.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ from collections.abc import Callable, Iterable, Sequence
from ctypes import _CData
from logging import Logger
from multiprocessing import queues, synchronize
from multiprocessing.pool import Pool as _Pool
from multiprocessing.process import BaseProcess
from multiprocessing.sharedctypes import SynchronizedArray, SynchronizedBase
from typing import Any, Type, TypeVar, Union, overload
Expand Down Expand Up @@ -57,7 +58,7 @@ class BaseContext(object):
initializer: Callable[..., Any] | None = ...,
initargs: Iterable[Any] = ...,
maxtasksperchild: int | None = ...,
) -> multiprocessing.pool.Pool: ...
) -> _Pool: ...
@overload
def RawValue(self, typecode_or_type: Type[_CT], *args: Any) -> _CT: ...
@overload
Expand Down
4 changes: 2 additions & 2 deletions mypy/typeshed/stdlib/parser.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def suite(source: str) -> STType: ...
def sequence2st(sequence: Sequence[Any]) -> STType: ...
def tuple2st(sequence: Sequence[Any]) -> STType: ...
def st2list(st: STType, line_info: bool = ..., col_info: bool = ...) -> list[Any]: ...
def st2tuple(st: STType, line_info: bool = ..., col_info: bool = ...) -> Tuple[Any]: ...
def st2tuple(st: STType, line_info: bool = ..., col_info: bool = ...) -> Tuple[Any, ...]: ...
def compilest(st: STType, filename: StrOrBytesPath = ...) -> CodeType: ...
def isexpr(st: STType) -> bool: ...
def issuite(st: STType) -> bool: ...
Expand All @@ -19,4 +19,4 @@ class STType:
def isexpr(self) -> bool: ...
def issuite(self) -> bool: ...
def tolist(self, line_info: bool = ..., col_info: bool = ...) -> list[Any]: ...
def totuple(self, line_info: bool = ..., col_info: bool = ...) -> Tuple[Any]: ...
def totuple(self, line_info: bool = ..., col_info: bool = ...) -> Tuple[Any, ...]: ...
Loading