From 369525071a548c03ddea1c428207c8801e73192f Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 14 Dec 2022 17:35:56 -0800 Subject: [PATCH] Sync typeshed (#14295) Source commit: https://github.com/python/typeshed/commit/9bddd3a3f1abfaf6335c2139a77ff1ff69eb4b54 --- mypy/typeshed/stdlib/_ast.pyi | 6 ++-- mypy/typeshed/stdlib/asyncio/runners.pyi | 9 +++++- mypy/typeshed/stdlib/email/message.pyi | 7 +++-- mypy/typeshed/stdlib/http/client.pyi | 8 +++++- .../stdlib/multiprocessing/context.pyi | 4 +-- mypy/typeshed/stdlib/multiprocessing/util.pyi | 4 +-- mypy/typeshed/stdlib/types.pyi | 2 +- mypy/typeshed/stdlib/typing.pyi | 7 +++-- mypy/typeshed/stdlib/unittest/case.pyi | 2 +- mypy/typeshed/stdlib/zipfile.pyi | 28 +++++++++++-------- 10 files changed, 51 insertions(+), 26 deletions(-) diff --git a/mypy/typeshed/stdlib/_ast.pyi b/mypy/typeshed/stdlib/_ast.pyi index f723b7eff8bb..7bc47266d713 100644 --- a/mypy/typeshed/stdlib/_ast.pyi +++ b/mypy/typeshed/stdlib/_ast.pyi @@ -104,14 +104,14 @@ class Assign(stmt): class AugAssign(stmt): if sys.version_info >= (3, 10): __match_args__ = ("target", "op", "value") - target: expr + target: Name | Attribute | Subscript op: operator value: expr class AnnAssign(stmt): if sys.version_info >= (3, 10): __match_args__ = ("target", "annotation", "value", "simple") - target: expr + target: Name | Attribute | Subscript annotation: expr value: expr | None simple: int @@ -355,7 +355,7 @@ if sys.version_info >= (3, 8): class NamedExpr(expr): if sys.version_info >= (3, 10): __match_args__ = ("target", "value") - target: expr + target: Name value: expr class Attribute(expr): diff --git a/mypy/typeshed/stdlib/asyncio/runners.pyi b/mypy/typeshed/stdlib/asyncio/runners.pyi index 49d236bbee9e..74ed83ed8dc4 100644 --- a/mypy/typeshed/stdlib/asyncio/runners.pyi +++ b/mypy/typeshed/stdlib/asyncio/runners.pyi @@ -3,6 +3,7 @@ from _typeshed import Self from collections.abc import Callable, Coroutine from contextvars import Context from typing import Any, TypeVar +from typing_extensions import final from .events import AbstractEventLoop @@ -13,6 +14,7 @@ else: _T = TypeVar("_T") if sys.version_info >= (3, 11): + @final class Runner: def __init__(self, *, debug: bool | None = ..., loop_factory: Callable[[], AbstractEventLoop] | None = ...) -> None: ... def __enter__(self: Self) -> Self: ... @@ -21,7 +23,12 @@ if sys.version_info >= (3, 11): def get_loop(self) -> AbstractEventLoop: ... def run(self, coro: Coroutine[Any, Any, _T], *, context: Context | None = ...) -> _T: ... -if sys.version_info >= (3, 8): +if sys.version_info >= (3, 12): + def run( + main: Coroutine[Any, Any, _T], *, debug: bool | None = ..., loop_factory: Callable[[], AbstractEventLoop] | None = ... + ) -> _T: ... + +elif sys.version_info >= (3, 8): def run(main: Coroutine[Any, Any, _T], *, debug: bool | None = ...) -> _T: ... else: diff --git a/mypy/typeshed/stdlib/email/message.pyi b/mypy/typeshed/stdlib/email/message.pyi index 3c59aeeb2d01..c6b77cdde054 100644 --- a/mypy/typeshed/stdlib/email/message.pyi +++ b/mypy/typeshed/stdlib/email/message.pyi @@ -5,7 +5,7 @@ from email.charset import Charset from email.contentmanager import ContentManager from email.errors import MessageDefect from email.policy import Policy -from typing import Any, TypeVar +from typing import Any, TypeVar, overload from typing_extensions import TypeAlias __all__ = ["Message", "EmailMessage"] @@ -54,7 +54,10 @@ class Message: def get_filename(self, failobj: _T = ...) -> _T | str: ... def get_boundary(self, failobj: _T = ...) -> _T | str: ... def set_boundary(self, boundary: str) -> None: ... - def get_content_charset(self, failobj: _T = ...) -> _T | str: ... + @overload + def get_content_charset(self) -> str | None: ... + @overload + def get_content_charset(self, failobj: _T) -> str | _T: ... def get_charsets(self, failobj: _T = ...) -> _T | list[str]: ... def walk(self: Self) -> Generator[Self, None, None]: ... def get_content_disposition(self) -> str | None: ... diff --git a/mypy/typeshed/stdlib/http/client.pyi b/mypy/typeshed/stdlib/http/client.pyi index ad794ed9b073..53cefc0a33d1 100644 --- a/mypy/typeshed/stdlib/http/client.pyi +++ b/mypy/typeshed/stdlib/http/client.pyi @@ -154,7 +154,13 @@ class HTTPConnection: blocksize: int = ..., ) -> None: ... def request( - self, method: str, url: str, body: _DataType | None = ..., headers: Mapping[str, str] = ..., *, encode_chunked: bool = ... + self, + method: str, + url: str, + body: _DataType | str | None = ..., + headers: Mapping[str, str] = ..., + *, + encode_chunked: bool = ..., ) -> None: ... def getresponse(self) -> HTTPResponse: ... def set_debuglevel(self, level: int) -> None: ... diff --git a/mypy/typeshed/stdlib/multiprocessing/context.pyi b/mypy/typeshed/stdlib/multiprocessing/context.pyi index f6380e2cfcbf..6622dca19ade 100644 --- a/mypy/typeshed/stdlib/multiprocessing/context.pyi +++ b/mypy/typeshed/stdlib/multiprocessing/context.pyi @@ -2,7 +2,7 @@ import ctypes import sys from collections.abc import Callable, Iterable, Sequence from ctypes import _CData -from logging import Logger +from logging import Logger, _Level as _LoggingLevel from multiprocessing import popen_fork, popen_forkserver, popen_spawn_posix, popen_spawn_win32, queues, synchronize from multiprocessing.managers import SyncManager from multiprocessing.pool import Pool as _Pool @@ -107,7 +107,7 @@ class BaseContext: ) -> Any: ... def freeze_support(self) -> None: ... def get_logger(self) -> Logger: ... - def log_to_stderr(self, level: str | None = ...) -> Logger: ... + def log_to_stderr(self, level: _LoggingLevel | None = ...) -> Logger: ... def allow_connection_pickling(self) -> None: ... def set_executable(self, executable: str) -> None: ... def set_forkserver_preload(self, module_names: list[str]) -> None: ... diff --git a/mypy/typeshed/stdlib/multiprocessing/util.pyi b/mypy/typeshed/stdlib/multiprocessing/util.pyi index 4b93b7a6a472..263781da9432 100644 --- a/mypy/typeshed/stdlib/multiprocessing/util.pyi +++ b/mypy/typeshed/stdlib/multiprocessing/util.pyi @@ -1,7 +1,7 @@ import threading from _typeshed import Incomplete, ReadableBuffer, SupportsTrunc from collections.abc import Callable, Iterable, Mapping, MutableMapping, Sequence -from logging import Logger +from logging import Logger, _Level as _LoggingLevel from typing import Any, SupportsInt from typing_extensions import SupportsIndex @@ -37,7 +37,7 @@ def debug(msg: object, *args: object) -> None: ... def info(msg: object, *args: object) -> None: ... def sub_warning(msg: object, *args: object) -> None: ... def get_logger() -> Logger: ... -def log_to_stderr(level: int | None = ...) -> Logger: ... +def log_to_stderr(level: _LoggingLevel | None = ...) -> Logger: ... def is_abstract_socket_namespace(address: str | bytes | None) -> bool: ... abstract_sockets_supported: bool diff --git a/mypy/typeshed/stdlib/types.pyi b/mypy/typeshed/stdlib/types.pyi index 4047cf84593d..a40b6280f47c 100644 --- a/mypy/typeshed/stdlib/types.pyi +++ b/mypy/typeshed/stdlib/types.pyi @@ -569,7 +569,7 @@ _P = ParamSpec("_P") # it's not really an Awaitable, but can be used in an await expression. Real type: Generator & Awaitable # The type: ignore is due to overlapping overloads, not the use of ParamSpec @overload -def coroutine(func: Callable[_P, Generator[_R, Any, Any]]) -> Callable[_P, Awaitable[_R]]: ... # type: ignore[misc] +def coroutine(func: Callable[_P, Generator[Any, Any, _R]]) -> Callable[_P, Awaitable[_R]]: ... # type: ignore[misc] @overload def coroutine(func: _Fn) -> _Fn: ... diff --git a/mypy/typeshed/stdlib/typing.pyi b/mypy/typeshed/stdlib/typing.pyi index cc27ae7dbda2..71018003b6d9 100644 --- a/mypy/typeshed/stdlib/typing.pyi +++ b/mypy/typeshed/stdlib/typing.pyi @@ -325,7 +325,7 @@ class SupportsRound(Protocol[_T_co]): def __round__(self, __ndigits: int) -> _T_co: ... @runtime_checkable -class Sized(Protocol): +class Sized(Protocol, metaclass=ABCMeta): @abstractmethod def __len__(self) -> int: ... @@ -452,7 +452,10 @@ class Container(Protocol[_T_co]): def __contains__(self, __x: object) -> bool: ... @runtime_checkable -class Collection(Sized, Iterable[_T_co], Container[_T_co], Protocol[_T_co]): ... +class Collection(Iterable[_T_co], Container[_T_co], Protocol[_T_co]): + # Implement Sized (but don't have it as a base class). + @abstractmethod + def __len__(self) -> int: ... class Sequence(Collection[_T_co], Reversible[_T_co], Generic[_T_co]): @overload diff --git a/mypy/typeshed/stdlib/unittest/case.pyi b/mypy/typeshed/stdlib/unittest/case.pyi index c75539a97368..42633ed13bb8 100644 --- a/mypy/typeshed/stdlib/unittest/case.pyi +++ b/mypy/typeshed/stdlib/unittest/case.pyi @@ -104,7 +104,7 @@ class TestCase: def tearDownClass(cls) -> None: ... def run(self, result: unittest.result.TestResult | None = ...) -> unittest.result.TestResult | None: ... def __call__(self, result: unittest.result.TestResult | None = ...) -> unittest.result.TestResult | None: ... - def skipTest(self, reason: Any) -> None: ... + def skipTest(self, reason: Any) -> NoReturn: ... def subTest(self, msg: Any = ..., **params: Any) -> AbstractContextManager[None]: ... def debug(self) -> None: ... if sys.version_info < (3, 11): diff --git a/mypy/typeshed/stdlib/zipfile.pyi b/mypy/typeshed/stdlib/zipfile.pyi index e964cd6eda87..60134c915da7 100644 --- a/mypy/typeshed/stdlib/zipfile.pyi +++ b/mypy/typeshed/stdlib/zipfile.pyi @@ -29,6 +29,7 @@ _DateTuple: TypeAlias = tuple[int, int, int, int, int, int] _ReadWriteMode: TypeAlias = Literal["r", "w"] _ReadWriteBinaryMode: TypeAlias = Literal["r", "w", "rb", "wb"] _ZipFileMode: TypeAlias = Literal["r", "w", "x", "a"] +_CompressionMode: TypeAlias = Literal[0, 8, 12, 14] class BadZipFile(Exception): ... @@ -100,7 +101,7 @@ class ZipFile: fp: IO[bytes] | None NameToInfo: dict[str, ZipInfo] start_dir: int # undocumented - compression: int # undocumented + compression: _CompressionMode # undocumented compresslevel: int | None # undocumented mode: _ZipFileMode # undocumented pwd: bytes | None # undocumented @@ -110,7 +111,7 @@ class ZipFile: self, file: StrPath | IO[bytes], mode: Literal["r"] = ..., - compression: int = ..., + compression: _CompressionMode = ..., allowZip64: bool = ..., compresslevel: int | None = ..., *, @@ -122,7 +123,7 @@ class ZipFile: self, file: StrPath | IO[bytes], mode: _ZipFileMode = ..., - compression: int = ..., + compression: _CompressionMode = ..., allowZip64: bool = ..., compresslevel: int | None = ..., *, @@ -134,7 +135,7 @@ class ZipFile: self, file: StrPath | IO[bytes], mode: _ZipFileMode = ..., - compression: int = ..., + compression: _CompressionMode = ..., allowZip64: bool = ..., compresslevel: int | None = ..., *, @@ -145,7 +146,7 @@ class ZipFile: self, file: StrPath | IO[bytes], mode: _ZipFileMode = ..., - compression: int = ..., + compression: _CompressionMode = ..., allowZip64: bool = ..., compresslevel: int | None = ..., ) -> None: ... @@ -184,14 +185,19 @@ class ZipFile: class PyZipFile(ZipFile): def __init__( - self, file: str | IO[bytes], mode: _ZipFileMode = ..., compression: int = ..., allowZip64: bool = ..., optimize: int = ... + self, + file: str | IO[bytes], + mode: _ZipFileMode = ..., + compression: _CompressionMode = ..., + allowZip64: bool = ..., + optimize: int = ..., ) -> None: ... def writepy(self, pathname: str, basename: str = ..., filterfunc: Callable[[str], bool] | None = ...) -> None: ... class ZipInfo: filename: str date_time: _DateTuple - compress_type: int + compress_type: _CompressionMode comment: bytes extra: bytes create_system: int @@ -269,10 +275,10 @@ if sys.version_info >= (3, 8): def is_zipfile(filename: StrOrBytesPath | _SupportsReadSeekTell) -> bool: ... -ZIP_STORED: int -ZIP_DEFLATED: int +ZIP_STORED: Literal[0] +ZIP_DEFLATED: Literal[8] ZIP64_LIMIT: int ZIP_FILECOUNT_LIMIT: int ZIP_MAX_COMMENT: int -ZIP_BZIP2: int -ZIP_LZMA: int +ZIP_BZIP2: Literal[12] +ZIP_LZMA: Literal[14]