From 69c774e6d6fa92aea8f32cd0e045e8a34a0f7215 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sat, 15 Apr 2023 13:37:00 -0700 Subject: [PATCH] Sync typeshed (#15055) Source commit: https://github.com/python/typeshed/commit/b0ed50e9392a23e52445b630a808153e0e256976 --- mypy/typeshed/stdlib/asyncio/base_events.pyi | 6 +- mypy/typeshed/stdlib/asyncio/events.pyi | 6 +- mypy/typeshed/stdlib/dataclasses.pyi | 22 +++++- mypy/typeshed/stdlib/pathlib.pyi | 4 +- mypy/typeshed/stdlib/sys.pyi | 14 ++++ mypy/typeshed/stdlib/tkinter/__init__.pyi | 72 ++++++++++---------- mypy/typeshed/stdlib/urllib/parse.pyi | 13 ++-- mypy/typeshed/stdlib/zipfile.pyi | 14 ++-- 8 files changed, 96 insertions(+), 55 deletions(-) diff --git a/mypy/typeshed/stdlib/asyncio/base_events.pyi b/mypy/typeshed/stdlib/asyncio/base_events.pyi index 3b8f286710b9..992f6af5c4a8 100644 --- a/mypy/typeshed/stdlib/asyncio/base_events.pyi +++ b/mypy/typeshed/stdlib/asyncio/base_events.pyi @@ -417,9 +417,9 @@ class BaseEventLoop(AbstractEventLoop): async def sock_connect(self, sock: socket, address: _Address) -> None: ... async def sock_accept(self, sock: socket) -> tuple[socket, _RetAddress]: ... if sys.version_info >= (3, 11): - async def sock_recvfrom(self, sock: socket, bufsize: int) -> bytes: ... - async def sock_recvfrom_into(self, sock: socket, buf: WriteableBuffer, nbytes: int = 0) -> int: ... - async def sock_sendto(self, sock: socket, data: ReadableBuffer, address: _Address) -> None: ... + async def sock_recvfrom(self, sock: socket, bufsize: int) -> tuple[bytes, _RetAddress]: ... + async def sock_recvfrom_into(self, sock: socket, buf: WriteableBuffer, nbytes: int = 0) -> tuple[int, _RetAddress]: ... + async def sock_sendto(self, sock: socket, data: ReadableBuffer, address: _Address) -> int: ... # Signal handling. def add_signal_handler(self, sig: int, callback: Callable[..., Any], *args: Any) -> None: ... def remove_signal_handler(self, sig: int) -> bool: ... diff --git a/mypy/typeshed/stdlib/asyncio/events.pyi b/mypy/typeshed/stdlib/asyncio/events.pyi index f97afe873c9f..34576b091edb 100644 --- a/mypy/typeshed/stdlib/asyncio/events.pyi +++ b/mypy/typeshed/stdlib/asyncio/events.pyi @@ -569,11 +569,11 @@ class AbstractEventLoop: async def sock_accept(self, sock: socket) -> tuple[socket, _RetAddress]: ... if sys.version_info >= (3, 11): @abstractmethod - async def sock_recvfrom(self, sock: socket, bufsize: int) -> bytes: ... + async def sock_recvfrom(self, sock: socket, bufsize: int) -> tuple[bytes, _RetAddress]: ... @abstractmethod - async def sock_recvfrom_into(self, sock: socket, buf: WriteableBuffer, nbytes: int = 0) -> int: ... + async def sock_recvfrom_into(self, sock: socket, buf: WriteableBuffer, nbytes: int = 0) -> tuple[int, _RetAddress]: ... @abstractmethod - async def sock_sendto(self, sock: socket, data: ReadableBuffer, address: _Address) -> None: ... + async def sock_sendto(self, sock: socket, data: ReadableBuffer, address: _Address) -> int: ... # Signal handling. @abstractmethod def add_signal_handler(self, sig: int, callback: Callable[..., object], *args: Any) -> None: ... diff --git a/mypy/typeshed/stdlib/dataclasses.pyi b/mypy/typeshed/stdlib/dataclasses.pyi index c97dc612c496..13cffcd70c0e 100644 --- a/mypy/typeshed/stdlib/dataclasses.pyi +++ b/mypy/typeshed/stdlib/dataclasses.pyi @@ -247,7 +247,27 @@ class InitVar(Generic[_T], metaclass=_InitVarMeta): @overload def __class_getitem__(cls, type: Any) -> InitVar[Any]: ... -if sys.version_info >= (3, 11): +if sys.version_info >= (3, 12): + def make_dataclass( + cls_name: str, + fields: Iterable[str | tuple[str, type] | tuple[str, type, Any]], + *, + bases: tuple[type, ...] = (), + namespace: dict[str, Any] | None = None, + init: bool = True, + repr: bool = True, + eq: bool = True, + order: bool = False, + unsafe_hash: bool = False, + frozen: bool = False, + match_args: bool = True, + kw_only: bool = False, + slots: bool = False, + weakref_slot: bool = False, + module: str | None = None, + ) -> type: ... + +elif sys.version_info >= (3, 11): def make_dataclass( cls_name: str, fields: Iterable[str | tuple[str, type] | tuple[str, type, Any]], diff --git a/mypy/typeshed/stdlib/pathlib.pyi b/mypy/typeshed/stdlib/pathlib.pyi index 114678ed574d..7aec66b584e3 100644 --- a/mypy/typeshed/stdlib/pathlib.pyi +++ b/mypy/typeshed/stdlib/pathlib.pyi @@ -173,9 +173,9 @@ class Path(PurePath): def resolve(self, strict: bool = False) -> Self: ... def rglob(self, pattern: str) -> Generator[Self, None, None]: ... def rmdir(self) -> None: ... - def symlink_to(self, target: str | Path, target_is_directory: bool = False) -> None: ... + def symlink_to(self, target: StrOrBytesPath, target_is_directory: bool = False) -> None: ... if sys.version_info >= (3, 10): - def hardlink_to(self, target: str | Path) -> None: ... + def hardlink_to(self, target: StrOrBytesPath) -> None: ... def touch(self, mode: int = 0o666, exist_ok: bool = True) -> None: ... if sys.version_info >= (3, 8): diff --git a/mypy/typeshed/stdlib/sys.pyi b/mypy/typeshed/stdlib/sys.pyi index 7dba4603b2ed..786db72c78ec 100644 --- a/mypy/typeshed/stdlib/sys.pyi +++ b/mypy/typeshed/stdlib/sys.pyi @@ -201,6 +201,20 @@ class _int_info(structseq[int], tuple[int, int, int, int]): @property def str_digits_check_threshold(self) -> int: ... +_ThreadInfoName: TypeAlias = Literal["nt", "pthread", "pthread-stubs", "solaris"] +_ThreadInfoLock: TypeAlias = Literal["semaphore", "mutex+cond"] | None + +@final +class _thread_info(_UninstantiableStructseq, tuple[_ThreadInfoName, _ThreadInfoLock, str | None]): + @property + def name(self) -> _ThreadInfoName: ... + @property + def lock(self) -> _ThreadInfoLock: ... + @property + def version(self) -> str | None: ... + +thread_info: _thread_info + @final class _version_info(_UninstantiableStructseq, tuple[int, int, int, str, int]): @property diff --git a/mypy/typeshed/stdlib/tkinter/__init__.pyi b/mypy/typeshed/stdlib/tkinter/__init__.pyi index ef63b7e19ba4..3291b0c9dd98 100644 --- a/mypy/typeshed/stdlib/tkinter/__init__.pyi +++ b/mypy/typeshed/stdlib/tkinter/__init__.pyi @@ -1234,16 +1234,16 @@ class Canvas(Widget, XView, YView): __x1: float, __y1: float, *, - activedash: str | list[int] | tuple[int, ...] = ..., + activedash: str | int | list[int] | tuple[int, ...] = ..., activefill: str = ..., activestipple: str = ..., activewidth: _ScreenUnits = ..., arrow: Literal["first", "last", "both"] = ..., arrowshape: tuple[float, float, float] = ..., capstyle: Literal["round", "projecting", "butt"] = ..., - dash: str | list[int] | tuple[int, ...] = ..., + dash: str | int | list[int] | tuple[int, ...] = ..., dashoffset: _ScreenUnits = ..., - disableddash: str | list[int] | tuple[int, ...] = ..., + disableddash: str | int | list[int] | tuple[int, ...] = ..., disabledfill: str = ..., disabledstipple: str = ..., disabledwidth: _ScreenUnits = ..., @@ -1263,16 +1263,16 @@ class Canvas(Widget, XView, YView): __xy_pair_0: tuple[float, float], __xy_pair_1: tuple[float, float], *, - activedash: str | list[int] | tuple[int, ...] = ..., + activedash: str | int | list[int] | tuple[int, ...] = ..., activefill: str = ..., activestipple: str = ..., activewidth: _ScreenUnits = ..., arrow: Literal["first", "last", "both"] = ..., arrowshape: tuple[float, float, float] = ..., capstyle: Literal["round", "projecting", "butt"] = ..., - dash: str | list[int] | tuple[int, ...] = ..., + dash: str | int | list[int] | tuple[int, ...] = ..., dashoffset: _ScreenUnits = ..., - disableddash: str | list[int] | tuple[int, ...] = ..., + disableddash: str | int | list[int] | tuple[int, ...] = ..., disabledfill: str = ..., disabledstipple: str = ..., disabledwidth: _ScreenUnits = ..., @@ -1298,16 +1298,16 @@ class Canvas(Widget, XView, YView): | list[tuple[float, float]] ), *, - activedash: str | list[int] | tuple[int, ...] = ..., + activedash: str | int | list[int] | tuple[int, ...] = ..., activefill: str = ..., activestipple: str = ..., activewidth: _ScreenUnits = ..., arrow: Literal["first", "last", "both"] = ..., arrowshape: tuple[float, float, float] = ..., capstyle: Literal["round", "projecting", "butt"] = ..., - dash: str | list[int] | tuple[int, ...] = ..., + dash: str | int | list[int] | tuple[int, ...] = ..., dashoffset: _ScreenUnits = ..., - disableddash: str | list[int] | tuple[int, ...] = ..., + disableddash: str | int | list[int] | tuple[int, ...] = ..., disabledfill: str = ..., disabledstipple: str = ..., disabledwidth: _ScreenUnits = ..., @@ -1329,15 +1329,15 @@ class Canvas(Widget, XView, YView): __x1: float, __y1: float, *, - activedash: str | list[int] | tuple[int, ...] = ..., + activedash: str | int | list[int] | tuple[int, ...] = ..., activefill: str = ..., activeoutline: str = ..., activeoutlinestipple: str = ..., activestipple: str = ..., activewidth: _ScreenUnits = ..., - dash: str | list[int] | tuple[int, ...] = ..., + dash: str | int | list[int] | tuple[int, ...] = ..., dashoffset: _ScreenUnits = ..., - disableddash: str | list[int] | tuple[int, ...] = ..., + disableddash: str | int | list[int] | tuple[int, ...] = ..., disabledfill: str = ..., disabledoutline: str = ..., disabledoutlinestipple: str = ..., @@ -1359,15 +1359,15 @@ class Canvas(Widget, XView, YView): __xy_pair_0: tuple[float, float], __xy_pair_1: tuple[float, float], *, - activedash: str | list[int] | tuple[int, ...] = ..., + activedash: str | int | list[int] | tuple[int, ...] = ..., activefill: str = ..., activeoutline: str = ..., activeoutlinestipple: str = ..., activestipple: str = ..., activewidth: _ScreenUnits = ..., - dash: str | list[int] | tuple[int, ...] = ..., + dash: str | int | list[int] | tuple[int, ...] = ..., dashoffset: _ScreenUnits = ..., - disableddash: str | list[int] | tuple[int, ...] = ..., + disableddash: str | int | list[int] | tuple[int, ...] = ..., disabledfill: str = ..., disabledoutline: str = ..., disabledoutlinestipple: str = ..., @@ -1395,15 +1395,15 @@ class Canvas(Widget, XView, YView): | list[tuple[float, float]] ), *, - activedash: str | list[int] | tuple[int, ...] = ..., + activedash: str | int | list[int] | tuple[int, ...] = ..., activefill: str = ..., activeoutline: str = ..., activeoutlinestipple: str = ..., activestipple: str = ..., activewidth: _ScreenUnits = ..., - dash: str | list[int] | tuple[int, ...] = ..., + dash: str | int | list[int] | tuple[int, ...] = ..., dashoffset: _ScreenUnits = ..., - disableddash: str | list[int] | tuple[int, ...] = ..., + disableddash: str | int | list[int] | tuple[int, ...] = ..., disabledfill: str = ..., disabledoutline: str = ..., disabledoutlinestipple: str = ..., @@ -1427,15 +1427,15 @@ class Canvas(Widget, XView, YView): __x1: float, __y1: float, *xy_pairs: float, - activedash: str | list[int] | tuple[int, ...] = ..., + activedash: str | int | list[int] | tuple[int, ...] = ..., activefill: str = ..., activeoutline: str = ..., activeoutlinestipple: str = ..., activestipple: str = ..., activewidth: _ScreenUnits = ..., - dash: str | list[int] | tuple[int, ...] = ..., + dash: str | int | list[int] | tuple[int, ...] = ..., dashoffset: _ScreenUnits = ..., - disableddash: str | list[int] | tuple[int, ...] = ..., + disableddash: str | int | list[int] | tuple[int, ...] = ..., disabledfill: str = ..., disabledoutline: str = ..., disabledoutlinestipple: str = ..., @@ -1460,15 +1460,15 @@ class Canvas(Widget, XView, YView): __xy_pair_0: tuple[float, float], __xy_pair_1: tuple[float, float], *xy_pairs: tuple[float, float], - activedash: str | list[int] | tuple[int, ...] = ..., + activedash: str | int | list[int] | tuple[int, ...] = ..., activefill: str = ..., activeoutline: str = ..., activeoutlinestipple: str = ..., activestipple: str = ..., activewidth: _ScreenUnits = ..., - dash: str | list[int] | tuple[int, ...] = ..., + dash: str | int | list[int] | tuple[int, ...] = ..., dashoffset: _ScreenUnits = ..., - disableddash: str | list[int] | tuple[int, ...] = ..., + disableddash: str | int | list[int] | tuple[int, ...] = ..., disabledfill: str = ..., disabledoutline: str = ..., disabledoutlinestipple: str = ..., @@ -1499,15 +1499,15 @@ class Canvas(Widget, XView, YView): | list[tuple[float, float]] ), *, - activedash: str | list[int] | tuple[int, ...] = ..., + activedash: str | int | list[int] | tuple[int, ...] = ..., activefill: str = ..., activeoutline: str = ..., activeoutlinestipple: str = ..., activestipple: str = ..., activewidth: _ScreenUnits = ..., - dash: str | list[int] | tuple[int, ...] = ..., + dash: str | int | list[int] | tuple[int, ...] = ..., dashoffset: _ScreenUnits = ..., - disableddash: str | list[int] | tuple[int, ...] = ..., + disableddash: str | int | list[int] | tuple[int, ...] = ..., disabledfill: str = ..., disabledoutline: str = ..., disabledoutlinestipple: str = ..., @@ -1534,15 +1534,15 @@ class Canvas(Widget, XView, YView): __x1: float, __y1: float, *, - activedash: str | list[int] | tuple[int, ...] = ..., + activedash: str | int | list[int] | tuple[int, ...] = ..., activefill: str = ..., activeoutline: str = ..., activeoutlinestipple: str = ..., activestipple: str = ..., activewidth: _ScreenUnits = ..., - dash: str | list[int] | tuple[int, ...] = ..., + dash: str | int | list[int] | tuple[int, ...] = ..., dashoffset: _ScreenUnits = ..., - disableddash: str | list[int] | tuple[int, ...] = ..., + disableddash: str | int | list[int] | tuple[int, ...] = ..., disabledfill: str = ..., disabledoutline: str = ..., disabledoutlinestipple: str = ..., @@ -1564,15 +1564,15 @@ class Canvas(Widget, XView, YView): __xy_pair_0: tuple[float, float], __xy_pair_1: tuple[float, float], *, - activedash: str | list[int] | tuple[int, ...] = ..., + activedash: str | int | list[int] | tuple[int, ...] = ..., activefill: str = ..., activeoutline: str = ..., activeoutlinestipple: str = ..., activestipple: str = ..., activewidth: _ScreenUnits = ..., - dash: str | list[int] | tuple[int, ...] = ..., + dash: str | int | list[int] | tuple[int, ...] = ..., dashoffset: _ScreenUnits = ..., - disableddash: str | list[int] | tuple[int, ...] = ..., + disableddash: str | int | list[int] | tuple[int, ...] = ..., disabledfill: str = ..., disabledoutline: str = ..., disabledoutlinestipple: str = ..., @@ -1600,15 +1600,15 @@ class Canvas(Widget, XView, YView): | list[tuple[float, float]] ), *, - activedash: str | list[int] | tuple[int, ...] = ..., + activedash: str | int | list[int] | tuple[int, ...] = ..., activefill: str = ..., activeoutline: str = ..., activeoutlinestipple: str = ..., activestipple: str = ..., activewidth: _ScreenUnits = ..., - dash: str | list[int] | tuple[int, ...] = ..., + dash: str | int | list[int] | tuple[int, ...] = ..., dashoffset: _ScreenUnits = ..., - disableddash: str | list[int] | tuple[int, ...] = ..., + disableddash: str | int | list[int] | tuple[int, ...] = ..., disabledfill: str = ..., disabledoutline: str = ..., disabledoutlinestipple: str = ..., diff --git a/mypy/typeshed/stdlib/urllib/parse.pyi b/mypy/typeshed/stdlib/urllib/parse.pyi index 8e179ca765b1..116754091d1a 100644 --- a/mypy/typeshed/stdlib/urllib/parse.pyi +++ b/mypy/typeshed/stdlib/urllib/parse.pyi @@ -196,14 +196,15 @@ else: url: bytes | bytearray | None, scheme: bytes | bytearray | None | Literal[""] = "", allow_fragments: bool = True ) -> SplitResultBytes: ... +# Requires an iterable of length 6 @overload -def urlunparse( - components: tuple[AnyStr | None, AnyStr | None, AnyStr | None, AnyStr | None, AnyStr | None, AnyStr | None] -) -> AnyStr: ... +def urlunparse(components: Iterable[None]) -> Literal[b""]: ... @overload -def urlunparse(components: Sequence[AnyStr | None]) -> AnyStr: ... +def urlunparse(components: Iterable[AnyStr | None]) -> AnyStr: ... + +# Requires an iterable of length 5 @overload -def urlunsplit(components: tuple[AnyStr | None, AnyStr | None, AnyStr | None, AnyStr | None, AnyStr | None]) -> AnyStr: ... +def urlunsplit(components: Iterable[None]) -> Literal[b""]: ... @overload -def urlunsplit(components: Sequence[AnyStr | None]) -> AnyStr: ... +def urlunsplit(components: Iterable[AnyStr | None]) -> AnyStr: ... def unwrap(url: str) -> str: ... diff --git a/mypy/typeshed/stdlib/zipfile.pyi b/mypy/typeshed/stdlib/zipfile.pyi index 6e632fbe6560..92f1dc49adbc 100644 --- a/mypy/typeshed/stdlib/zipfile.pyi +++ b/mypy/typeshed/stdlib/zipfile.pyi @@ -222,10 +222,11 @@ class ZipInfo: def is_dir(self) -> bool: ... def FileHeader(self, zip64: bool | None = None) -> bytes: ... -class _PathOpenProtocol(Protocol): - def __call__(self, mode: _ReadWriteMode = ..., pwd: bytes | None = ..., *, force_zip64: bool = ...) -> IO[bytes]: ... - if sys.version_info >= (3, 8): + if sys.version_info < (3, 9): + class _PathOpenProtocol(Protocol): + def __call__(self, mode: _ReadWriteMode = "r", pwd: bytes | None = ..., *, force_zip64: bool = ...) -> IO[bytes]: ... + class Path: @property def name(self) -> str: ... @@ -245,7 +246,12 @@ if sys.version_info >= (3, 8): def __init__(self, root: ZipFile | StrPath | IO[bytes], at: str = "") -> None: ... if sys.version_info >= (3, 9): def open( - self, mode: _ReadWriteBinaryMode = "r", *args: Any, pwd: bytes | None = None, **kwargs: Any + self, + mode: _ReadWriteBinaryMode = "r", + encoding: str | None = None, + *args: Any, + pwd: bytes | None = None, + **kwargs: Any, ) -> IO[bytes]: ... else: @property