From 519d7af3e8d229b97bdab1de3727b6e307243a39 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Sat, 9 Oct 2021 11:59:55 +0300 Subject: [PATCH] Sync typeshed Source commit: https://github.com/python/typeshed/commit/ca983cd319cb58b0a8fa3a086fad5e75332e0450 --- mypy/typeshed/stdlib/_typeshed/__init__.pyi | 10 +- mypy/typeshed/stdlib/builtins.pyi | 103 +++++++++++++----- mypy/typeshed/stdlib/collections/__init__.pyi | 6 +- mypy/typeshed/stdlib/contextlib.pyi | 6 +- mypy/typeshed/stdlib/ctypes/__init__.pyi | 13 +-- mypy/typeshed/stdlib/enum.pyi | 6 +- mypy/typeshed/stdlib/fcntl.pyi | 15 +-- mypy/typeshed/stdlib/importlib/machinery.pyi | 4 + mypy/typeshed/stdlib/inspect.pyi | 4 +- mypy/typeshed/stdlib/logging/handlers.pyi | 4 +- .../stdlib/multiprocessing/context.pyi | 3 +- mypy/typeshed/stdlib/parser.pyi | 4 +- mypy/typeshed/stdlib/pickle.pyi | 42 +++++-- mypy/typeshed/stdlib/plistlib.pyi | 18 ++- mypy/typeshed/stdlib/string.pyi | 12 ++ mypy/typeshed/stdlib/sys.pyi | 2 +- mypy/typeshed/stdlib/tkinter/__init__.pyi | 2 +- mypy/typeshed/stdlib/tkinter/ttk.pyi | 4 +- mypy/typeshed/stdlib/traceback.pyi | 2 +- mypy/typeshed/stdlib/types.pyi | 3 + mypy/typeshed/stdlib/typing.pyi | 5 +- mypy/typeshed/stdlib/unittest/mock.pyi | 10 +- mypy/typeshed/stdlib/urllib/response.pyi | 8 +- 23 files changed, 194 insertions(+), 92 deletions(-) diff --git a/mypy/typeshed/stdlib/_typeshed/__init__.pyi b/mypy/typeshed/stdlib/_typeshed/__init__.pyi index 3f8978a64623..9e60fd07e017 100644 --- a/mypy/typeshed/stdlib/_typeshed/__init__.pyi +++ b/mypy/typeshed/stdlib/_typeshed/__init__.pyi @@ -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 @@ -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): diff --git a/mypy/typeshed/stdlib/builtins.pyi b/mypy/typeshed/stdlib/builtins.pyi index fe8b35ac5100..75da5c830059 100644 --- a/mypy/typeshed/stdlib/builtins.pyi +++ b/mypy/typeshed/stdlib/builtins.pyi @@ -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: ... diff --git a/mypy/typeshed/stdlib/collections/__init__.pyi b/mypy/typeshed/stdlib/collections/__init__.pyi index 2cfd187eb35a..2aa0bf76d501 100644 --- a/mypy/typeshed/stdlib/collections/__init__.pyi +++ b/mypy/typeshed/stdlib/collections/__init__.pyi @@ -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: ... diff --git a/mypy/typeshed/stdlib/contextlib.pyi b/mypy/typeshed/stdlib/contextlib.pyi index 69f62575633c..8c362cfd1633 100644 --- a/mypy/typeshed/stdlib/contextlib.pyi +++ b/mypy/typeshed/stdlib/contextlib.pyi @@ -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: ... @@ -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]: ... diff --git a/mypy/typeshed/stdlib/ctypes/__init__.pyi b/mypy/typeshed/stdlib/ctypes/__init__.pyi index 03e9affd5267..696705833547 100644 --- a/mypy/typeshed/stdlib/ctypes/__init__.pyi +++ b/mypy/typeshed/stdlib/ctypes/__init__.pyi @@ -1,5 +1,5 @@ import sys -from array import array +from _typeshed import ReadableBuffer, WriteableBuffer from typing import ( Any, Callable, @@ -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 @@ -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 diff --git a/mypy/typeshed/stdlib/enum.pyi b/mypy/typeshed/stdlib/enum.pyi index 426bda857193..07fea104cec7 100644 --- a/mypy/typeshed/stdlib/enum.pyi +++ b/mypy/typeshed/stdlib/enum.pyi @@ -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): diff --git a/mypy/typeshed/stdlib/fcntl.pyi b/mypy/typeshed/stdlib/fcntl.pyi index ebaa31749528..141f9ee9360a 100644 --- a/mypy/typeshed/stdlib/fcntl.pyi +++ b/mypy/typeshed/stdlib/fcntl.pyi @@ -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 @@ -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: ... diff --git a/mypy/typeshed/stdlib/importlib/machinery.pyi b/mypy/typeshed/stdlib/importlib/machinery.pyi index a2e89bb2d8de..30194f6f2ad6 100644 --- a/mypy/typeshed/stdlib/importlib/machinery.pyi +++ b/mypy/typeshed/stdlib/importlib/machinery.pyi @@ -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: ... diff --git a/mypy/typeshed/stdlib/inspect.pyi b/mypy/typeshed/stdlib/inspect.pyi index 005222646133..e14718777a6e 100644 --- a/mypy/typeshed/stdlib/inspect.pyi +++ b/mypy/typeshed/stdlib/inspect.pyi @@ -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? @@ -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 diff --git a/mypy/typeshed/stdlib/logging/handlers.pyi b/mypy/typeshed/stdlib/logging/handlers.pyi index 762359bc17bb..5be624872a14 100644 --- a/mypy/typeshed/stdlib/logging/handlers.pyi +++ b/mypy/typeshed/stdlib/logging/handlers.pyi @@ -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, @@ -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 diff --git a/mypy/typeshed/stdlib/multiprocessing/context.pyi b/mypy/typeshed/stdlib/multiprocessing/context.pyi index 59ff0afadbc4..e65a387819bc 100644 --- a/mypy/typeshed/stdlib/multiprocessing/context.pyi +++ b/mypy/typeshed/stdlib/multiprocessing/context.pyi @@ -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 @@ -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 diff --git a/mypy/typeshed/stdlib/parser.pyi b/mypy/typeshed/stdlib/parser.pyi index cefcad5b08f1..aecf3244ca8d 100644 --- a/mypy/typeshed/stdlib/parser.pyi +++ b/mypy/typeshed/stdlib/parser.pyi @@ -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: ... @@ -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, ...]: ... diff --git a/mypy/typeshed/stdlib/pickle.pyi b/mypy/typeshed/stdlib/pickle.pyi index 19564f31178e..da6c5d11794a 100644 --- a/mypy/typeshed/stdlib/pickle.pyi +++ b/mypy/typeshed/stdlib/pickle.pyi @@ -1,11 +1,18 @@ import sys -from typing import IO, Any, Callable, ClassVar, Iterable, Iterator, Mapping, Optional, Tuple, Type, Union +from typing import Any, Callable, ClassVar, Iterable, Iterator, Mapping, Optional, Protocol, Tuple, Type, Union HIGHEST_PROTOCOL: int DEFAULT_PROTOCOL: int bytes_types: Tuple[Type[Any], ...] # undocumented +class _ReadableFileobj(Protocol): + def read(self, __n: int) -> bytes: ... + def readline(self) -> bytes: ... + +class _WritableFileobj(Protocol): + def write(self, __b: bytes) -> Any: ... + if sys.version_info >= (3, 8): # TODO: holistic design for buffer interface (typing.Buffer?) class PickleBuffer: @@ -15,22 +22,32 @@ if sys.version_info >= (3, 8): def release(self) -> None: ... _BufferCallback = Optional[Callable[[PickleBuffer], Any]] def dump( - obj: Any, file: IO[bytes], protocol: int | None = ..., *, fix_imports: bool = ..., buffer_callback: _BufferCallback = ... + obj: Any, + file: _WritableFileobj, + protocol: int | None = ..., + *, + fix_imports: bool = ..., + buffer_callback: _BufferCallback = ..., ) -> None: ... def dumps( obj: Any, protocol: int | None = ..., *, fix_imports: bool = ..., buffer_callback: _BufferCallback = ... ) -> bytes: ... def load( - file: IO[bytes], *, fix_imports: bool = ..., encoding: str = ..., errors: str = ..., buffers: Iterable[Any] | None = ... + file: _ReadableFileobj, + *, + fix_imports: bool = ..., + encoding: str = ..., + errors: str = ..., + buffers: Iterable[Any] | None = ..., ) -> Any: ... def loads( __data: bytes, *, fix_imports: bool = ..., encoding: str = ..., errors: str = ..., buffers: Iterable[Any] | None = ... ) -> Any: ... else: - def dump(obj: Any, file: IO[bytes], protocol: int | None = ..., *, fix_imports: bool = ...) -> None: ... + def dump(obj: Any, file: _WritableFileobj, protocol: int | None = ..., *, fix_imports: bool = ...) -> None: ... def dumps(obj: Any, protocol: int | None = ..., *, fix_imports: bool = ...) -> bytes: ... - def load(file: IO[bytes], *, fix_imports: bool = ..., encoding: str = ..., errors: str = ...) -> Any: ... + def load(file: _ReadableFileobj, *, fix_imports: bool = ..., encoding: str = ..., errors: str = ...) -> Any: ... def loads(data: bytes, *, fix_imports: bool = ..., encoding: str = ..., errors: str = ...) -> Any: ... class PickleError(Exception): ... @@ -53,11 +70,16 @@ class Pickler: if sys.version_info >= (3, 8): def __init__( - self, file: IO[bytes], protocol: int | None = ..., *, fix_imports: bool = ..., buffer_callback: _BufferCallback = ... + self, + file: _WritableFileobj, + protocol: int | None = ..., + *, + fix_imports: bool = ..., + buffer_callback: _BufferCallback = ..., ) -> None: ... def reducer_override(self, obj: Any) -> Any: ... else: - def __init__(self, file: IO[bytes], protocol: int | None = ..., *, fix_imports: bool = ...) -> None: ... + def __init__(self, file: _WritableFileobj, protocol: int | None = ..., *, fix_imports: bool = ...) -> None: ... def dump(self, __obj: Any) -> None: ... def clear_memo(self) -> None: ... def persistent_id(self, obj: Any) -> Any: ... @@ -68,7 +90,7 @@ class Unpickler: if sys.version_info >= (3, 8): def __init__( self, - file: IO[bytes], + file: _ReadableFileobj, *, fix_imports: bool = ..., encoding: str = ..., @@ -76,7 +98,9 @@ class Unpickler: buffers: Iterable[Any] | None = ..., ) -> None: ... else: - def __init__(self, file: IO[bytes], *, fix_imports: bool = ..., encoding: str = ..., errors: str = ...) -> None: ... + def __init__( + self, file: _ReadableFileobj, *, fix_imports: bool = ..., encoding: str = ..., errors: str = ... + ) -> None: ... def load(self) -> Any: ... def find_class(self, __module_name: str, __global_name: str) -> Any: ... def persistent_load(self, pid: Any) -> Any: ... diff --git a/mypy/typeshed/stdlib/plistlib.pyi b/mypy/typeshed/stdlib/plistlib.pyi index 3b5c2b78c81a..93d4fdc2480a 100644 --- a/mypy/typeshed/stdlib/plistlib.pyi +++ b/mypy/typeshed/stdlib/plistlib.pyi @@ -1,6 +1,7 @@ import sys +from datetime import datetime from enum import Enum -from typing import IO, Any, Dict as _Dict, Mapping, MutableMapping, Type +from typing import IO, Any, Dict as _Dict, List, Mapping, MutableMapping, Tuple, Type class PlistFormat(Enum): FMT_XML: int @@ -30,9 +31,20 @@ else: ) -> Any: ... def dump( - value: Mapping[str, Any], fp: IO[bytes], *, fmt: PlistFormat = ..., sort_keys: bool = ..., skipkeys: bool = ... + value: Mapping[str, Any] | List[Any] | Tuple[Any, ...] | str | bool | float | bytes | datetime, + fp: IO[bytes], + *, + fmt: PlistFormat = ..., + sort_keys: bool = ..., + skipkeys: bool = ..., ) -> None: ... -def dumps(value: Mapping[str, Any], *, fmt: PlistFormat = ..., skipkeys: bool = ..., sort_keys: bool = ...) -> bytes: ... +def dumps( + value: Mapping[str, Any] | List[Any] | Tuple[Any, ...] | str | bool | float | bytes | datetime, + *, + fmt: PlistFormat = ..., + skipkeys: bool = ..., + sort_keys: bool = ..., +) -> bytes: ... if sys.version_info < (3, 9): def readPlist(pathOrFile: str | IO[bytes]) -> Any: ... diff --git a/mypy/typeshed/stdlib/string.pyi b/mypy/typeshed/stdlib/string.pyi index ceed38f00931..321b2647fbb2 100644 --- a/mypy/typeshed/stdlib/string.pyi +++ b/mypy/typeshed/stdlib/string.pyi @@ -1,5 +1,12 @@ +import sys +from re import RegexFlag from typing import Any, Iterable, Mapping, Sequence, Tuple +if sys.version_info >= (3, 8): + from re import Pattern +else: + from typing import Pattern + ascii_letters: str ascii_lowercase: str ascii_uppercase: str @@ -14,6 +21,11 @@ def capwords(s: str, sep: str | None = ...) -> str: ... class Template: template: str + delimiter: str + idpattern: str + braceidpattern: str | None + flags: RegexFlag + pattern: Pattern[str] def __init__(self, template: str) -> None: ... def substitute(self, __mapping: Mapping[str, object] = ..., **kwds: object) -> str: ... def safe_substitute(self, __mapping: Mapping[str, object] = ..., **kwds: object) -> str: ... diff --git a/mypy/typeshed/stdlib/sys.pyi b/mypy/typeshed/stdlib/sys.pyi index e60a58c02ef2..5ccf9dff714c 100644 --- a/mypy/typeshed/stdlib/sys.pyi +++ b/mypy/typeshed/stdlib/sys.pyi @@ -47,7 +47,7 @@ if sys.platform == "win32": dllhandle: int dont_write_bytecode: bool displayhook: Callable[[object], Any] -excepthook: Callable[[Type[BaseException], BaseException, TracebackType], Any] +excepthook: Callable[[Type[BaseException], BaseException, TracebackType | None], Any] exec_prefix: str executable: str float_repr_style: str diff --git a/mypy/typeshed/stdlib/tkinter/__init__.pyi b/mypy/typeshed/stdlib/tkinter/__init__.pyi index b7a5d3a112cc..9ca63924f1ef 100644 --- a/mypy/typeshed/stdlib/tkinter/__init__.pyi +++ b/mypy/typeshed/stdlib/tkinter/__init__.pyi @@ -610,7 +610,7 @@ class Wm: withdraw = wm_withdraw class _ExceptionReportingCallback(Protocol): - def __call__(self, __exc: Type[BaseException], __val: BaseException, __tb: TracebackType) -> Any: ... + def __call__(self, __exc: Type[BaseException], __val: BaseException, __tb: TracebackType | None) -> Any: ... class Tk(Misc, Wm): master: None diff --git a/mypy/typeshed/stdlib/tkinter/ttk.pyi b/mypy/typeshed/stdlib/tkinter/ttk.pyi index 9569239a7861..cb7a7b63d0f4 100644 --- a/mypy/typeshed/stdlib/tkinter/ttk.pyi +++ b/mypy/typeshed/stdlib/tkinter/ttk.pyi @@ -933,7 +933,7 @@ class Treeview(Widget, tkinter.XView, tkinter.YView): # # 'tree headings' is same as ['tree', 'headings'], and I wouldn't be # surprised if someone was using it. - show: Literal["tree", "headings", "tree headings"] | tkinter._TkinterSequence[str] = ..., + show: Literal["tree", "headings", "tree headings", ""] | tkinter._TkinterSequence[str] = ..., style: str = ..., takefocus: tkinter._TakeFocusValue = ..., xscrollcommand: tkinter._XYScrollCommand = ..., @@ -950,7 +950,7 @@ class Treeview(Widget, tkinter.XView, tkinter.YView): height: int = ..., padding: tkinter._Padding = ..., selectmode: Literal["extended", "browse", "none"] = ..., - show: Literal["tree", "headings", "tree headings"] | tkinter._TkinterSequence[str] = ..., + show: Literal["tree", "headings", "tree headings", ""] | tkinter._TkinterSequence[str] = ..., style: str = ..., takefocus: tkinter._TakeFocusValue = ..., xscrollcommand: tkinter._XYScrollCommand = ..., diff --git a/mypy/typeshed/stdlib/traceback.pyi b/mypy/typeshed/stdlib/traceback.pyi index e071a3158816..a6474a13aeae 100644 --- a/mypy/typeshed/stdlib/traceback.pyi +++ b/mypy/typeshed/stdlib/traceback.pyi @@ -146,7 +146,7 @@ class StackSummary(List[FrameSummary]): @classmethod def extract( cls, - frame_gen: Generator[Tuple[FrameType, int], None, None], + frame_gen: Iterable[Tuple[FrameType, int]], *, limit: int | None = ..., lookup_lines: bool = ..., diff --git a/mypy/typeshed/stdlib/types.pyi b/mypy/typeshed/stdlib/types.pyi index 7cd99a429461..26d8263ead21 100644 --- a/mypy/typeshed/stdlib/types.pyi +++ b/mypy/typeshed/stdlib/types.pyi @@ -212,11 +212,14 @@ class AsyncGeneratorType(AsyncGenerator[_T_co, _T_contra]): @final class CoroutineType: + __name__: str + __qualname__: str cr_await: Any | None cr_code: CodeType cr_frame: FrameType cr_running: bool def close(self) -> None: ... + def __await__(self) -> Generator[Any, None, Any]: ... def send(self, __arg: Any) -> Any: ... @overload def throw(self, __typ: Type[BaseException], __val: BaseException | object = ..., __tb: TracebackType | None = ...) -> Any: ... diff --git a/mypy/typeshed/stdlib/typing.pyi b/mypy/typeshed/stdlib/typing.pyi index b87788667c37..4dc92e0ff9d9 100644 --- a/mypy/typeshed/stdlib/typing.pyi +++ b/mypy/typeshed/stdlib/typing.pyi @@ -667,7 +667,10 @@ class NamedTuple(Tuple[Any, ...]): _field_defaults: dict[str, Any] _fields: Tuple[str, ...] _source: str - def __init__(self, typename: str, fields: Iterable[Tuple[str, Any]] = ..., **kwargs: Any) -> None: ... + @overload + def __init__(self, typename: str, fields: Iterable[Tuple[str, Any]] = ...) -> None: ... + @overload + def __init__(self, typename: str, fields: None = ..., **kwargs: Any) -> None: ... @classmethod def _make(cls: Type[_T], iterable: Iterable[Any]) -> _T: ... if sys.version_info >= (3, 8): diff --git a/mypy/typeshed/stdlib/unittest/mock.pyi b/mypy/typeshed/stdlib/unittest/mock.pyi index 7ccaf3acaeb5..5b3816d047d3 100644 --- a/mypy/typeshed/stdlib/unittest/mock.pyi +++ b/mypy/typeshed/stdlib/unittest/mock.pyi @@ -1,7 +1,6 @@ import sys from typing import Any, Callable, Generic, Iterable, List, Mapping, Sequence, Tuple, Type, TypeVar, overload -_F = TypeVar("_F", bound=Callable[..., Any]) _T = TypeVar("_T") _TT = TypeVar("_TT", bound=Type[Any]) _R = TypeVar("_R") @@ -176,9 +175,12 @@ class _patch(Generic[_T]): kwargs: Mapping[str, Any], ) -> None: ... def copy(self) -> _patch[_T]: ... + @overload + def __call__(self, func: _TT) -> _TT: ... + @overload def __call__(self, func: Callable[..., _R]) -> Callable[..., _R]: ... def decorate_class(self, klass: _TT) -> _TT: ... - def decorate_callable(self, func: _F) -> _F: ... + def decorate_callable(self, func: Callable[..., _R]) -> Callable[..., _R]: ... def get_original(self) -> Tuple[Any, bool]: ... target: Any temp_original: Any @@ -318,8 +320,8 @@ class _patcher: spec_set: Any | None = ..., autospec: Any | None = ..., new_callable: Any | None = ..., - **kwargs: _T, - ) -> _patch[_T]: ... + **kwargs: Any, + ) -> _patch[Any]: ... def stopall(self) -> None: ... patch: _patcher diff --git a/mypy/typeshed/stdlib/urllib/response.pyi b/mypy/typeshed/stdlib/urllib/response.pyi index dd8a80833ba3..647ebf874432 100644 --- a/mypy/typeshed/stdlib/urllib/response.pyi +++ b/mypy/typeshed/stdlib/urllib/response.pyi @@ -1,3 +1,4 @@ +import sys from _typeshed import Self from email.message import Message from types import TracebackType @@ -46,7 +47,10 @@ class addinfo(addbase): class addinfourl(addinfo): url: str - code: int + code: int | None + if sys.version_info >= (3, 9): + @property + def status(self) -> int | None: ... def __init__(self, fp: IO[bytes], headers: Message, url: str, code: int | None = ...) -> None: ... def geturl(self) -> str: ... - def getcode(self) -> int: ... + def getcode(self) -> int | None: ...