Skip to content

Commit 3695250

Browse files
Sync typeshed (#14295)
Source commit: python/typeshed@9bddd3a
1 parent d62be28 commit 3695250

File tree

10 files changed

+51
-26
lines changed

10 files changed

+51
-26
lines changed

mypy/typeshed/stdlib/_ast.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,14 @@ class Assign(stmt):
104104
class AugAssign(stmt):
105105
if sys.version_info >= (3, 10):
106106
__match_args__ = ("target", "op", "value")
107-
target: expr
107+
target: Name | Attribute | Subscript
108108
op: operator
109109
value: expr
110110

111111
class AnnAssign(stmt):
112112
if sys.version_info >= (3, 10):
113113
__match_args__ = ("target", "annotation", "value", "simple")
114-
target: expr
114+
target: Name | Attribute | Subscript
115115
annotation: expr
116116
value: expr | None
117117
simple: int
@@ -355,7 +355,7 @@ if sys.version_info >= (3, 8):
355355
class NamedExpr(expr):
356356
if sys.version_info >= (3, 10):
357357
__match_args__ = ("target", "value")
358-
target: expr
358+
target: Name
359359
value: expr
360360

361361
class Attribute(expr):

mypy/typeshed/stdlib/asyncio/runners.pyi

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ from _typeshed import Self
33
from collections.abc import Callable, Coroutine
44
from contextvars import Context
55
from typing import Any, TypeVar
6+
from typing_extensions import final
67

78
from .events import AbstractEventLoop
89

@@ -13,6 +14,7 @@ else:
1314
_T = TypeVar("_T")
1415

1516
if sys.version_info >= (3, 11):
17+
@final
1618
class Runner:
1719
def __init__(self, *, debug: bool | None = ..., loop_factory: Callable[[], AbstractEventLoop] | None = ...) -> None: ...
1820
def __enter__(self: Self) -> Self: ...
@@ -21,7 +23,12 @@ if sys.version_info >= (3, 11):
2123
def get_loop(self) -> AbstractEventLoop: ...
2224
def run(self, coro: Coroutine[Any, Any, _T], *, context: Context | None = ...) -> _T: ...
2325

24-
if sys.version_info >= (3, 8):
26+
if sys.version_info >= (3, 12):
27+
def run(
28+
main: Coroutine[Any, Any, _T], *, debug: bool | None = ..., loop_factory: Callable[[], AbstractEventLoop] | None = ...
29+
) -> _T: ...
30+
31+
elif sys.version_info >= (3, 8):
2532
def run(main: Coroutine[Any, Any, _T], *, debug: bool | None = ...) -> _T: ...
2633

2734
else:

mypy/typeshed/stdlib/email/message.pyi

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ from email.charset import Charset
55
from email.contentmanager import ContentManager
66
from email.errors import MessageDefect
77
from email.policy import Policy
8-
from typing import Any, TypeVar
8+
from typing import Any, TypeVar, overload
99
from typing_extensions import TypeAlias
1010

1111
__all__ = ["Message", "EmailMessage"]
@@ -54,7 +54,10 @@ class Message:
5454
def get_filename(self, failobj: _T = ...) -> _T | str: ...
5555
def get_boundary(self, failobj: _T = ...) -> _T | str: ...
5656
def set_boundary(self, boundary: str) -> None: ...
57-
def get_content_charset(self, failobj: _T = ...) -> _T | str: ...
57+
@overload
58+
def get_content_charset(self) -> str | None: ...
59+
@overload
60+
def get_content_charset(self, failobj: _T) -> str | _T: ...
5861
def get_charsets(self, failobj: _T = ...) -> _T | list[str]: ...
5962
def walk(self: Self) -> Generator[Self, None, None]: ...
6063
def get_content_disposition(self) -> str | None: ...

mypy/typeshed/stdlib/http/client.pyi

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,13 @@ class HTTPConnection:
154154
blocksize: int = ...,
155155
) -> None: ...
156156
def request(
157-
self, method: str, url: str, body: _DataType | None = ..., headers: Mapping[str, str] = ..., *, encode_chunked: bool = ...
157+
self,
158+
method: str,
159+
url: str,
160+
body: _DataType | str | None = ...,
161+
headers: Mapping[str, str] = ...,
162+
*,
163+
encode_chunked: bool = ...,
158164
) -> None: ...
159165
def getresponse(self) -> HTTPResponse: ...
160166
def set_debuglevel(self, level: int) -> None: ...

mypy/typeshed/stdlib/multiprocessing/context.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import ctypes
22
import sys
33
from collections.abc import Callable, Iterable, Sequence
44
from ctypes import _CData
5-
from logging import Logger
5+
from logging import Logger, _Level as _LoggingLevel
66
from multiprocessing import popen_fork, popen_forkserver, popen_spawn_posix, popen_spawn_win32, queues, synchronize
77
from multiprocessing.managers import SyncManager
88
from multiprocessing.pool import Pool as _Pool
@@ -107,7 +107,7 @@ class BaseContext:
107107
) -> Any: ...
108108
def freeze_support(self) -> None: ...
109109
def get_logger(self) -> Logger: ...
110-
def log_to_stderr(self, level: str | None = ...) -> Logger: ...
110+
def log_to_stderr(self, level: _LoggingLevel | None = ...) -> Logger: ...
111111
def allow_connection_pickling(self) -> None: ...
112112
def set_executable(self, executable: str) -> None: ...
113113
def set_forkserver_preload(self, module_names: list[str]) -> None: ...

mypy/typeshed/stdlib/multiprocessing/util.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import threading
22
from _typeshed import Incomplete, ReadableBuffer, SupportsTrunc
33
from collections.abc import Callable, Iterable, Mapping, MutableMapping, Sequence
4-
from logging import Logger
4+
from logging import Logger, _Level as _LoggingLevel
55
from typing import Any, SupportsInt
66
from typing_extensions import SupportsIndex
77

@@ -37,7 +37,7 @@ def debug(msg: object, *args: object) -> None: ...
3737
def info(msg: object, *args: object) -> None: ...
3838
def sub_warning(msg: object, *args: object) -> None: ...
3939
def get_logger() -> Logger: ...
40-
def log_to_stderr(level: int | None = ...) -> Logger: ...
40+
def log_to_stderr(level: _LoggingLevel | None = ...) -> Logger: ...
4141
def is_abstract_socket_namespace(address: str | bytes | None) -> bool: ...
4242

4343
abstract_sockets_supported: bool

mypy/typeshed/stdlib/types.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ _P = ParamSpec("_P")
569569
# it's not really an Awaitable, but can be used in an await expression. Real type: Generator & Awaitable
570570
# The type: ignore is due to overlapping overloads, not the use of ParamSpec
571571
@overload
572-
def coroutine(func: Callable[_P, Generator[_R, Any, Any]]) -> Callable[_P, Awaitable[_R]]: ... # type: ignore[misc]
572+
def coroutine(func: Callable[_P, Generator[Any, Any, _R]]) -> Callable[_P, Awaitable[_R]]: ... # type: ignore[misc]
573573
@overload
574574
def coroutine(func: _Fn) -> _Fn: ...
575575

mypy/typeshed/stdlib/typing.pyi

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ class SupportsRound(Protocol[_T_co]):
325325
def __round__(self, __ndigits: int) -> _T_co: ...
326326

327327
@runtime_checkable
328-
class Sized(Protocol):
328+
class Sized(Protocol, metaclass=ABCMeta):
329329
@abstractmethod
330330
def __len__(self) -> int: ...
331331

@@ -452,7 +452,10 @@ class Container(Protocol[_T_co]):
452452
def __contains__(self, __x: object) -> bool: ...
453453

454454
@runtime_checkable
455-
class Collection(Sized, Iterable[_T_co], Container[_T_co], Protocol[_T_co]): ...
455+
class Collection(Iterable[_T_co], Container[_T_co], Protocol[_T_co]):
456+
# Implement Sized (but don't have it as a base class).
457+
@abstractmethod
458+
def __len__(self) -> int: ...
456459

457460
class Sequence(Collection[_T_co], Reversible[_T_co], Generic[_T_co]):
458461
@overload

mypy/typeshed/stdlib/unittest/case.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class TestCase:
104104
def tearDownClass(cls) -> None: ...
105105
def run(self, result: unittest.result.TestResult | None = ...) -> unittest.result.TestResult | None: ...
106106
def __call__(self, result: unittest.result.TestResult | None = ...) -> unittest.result.TestResult | None: ...
107-
def skipTest(self, reason: Any) -> None: ...
107+
def skipTest(self, reason: Any) -> NoReturn: ...
108108
def subTest(self, msg: Any = ..., **params: Any) -> AbstractContextManager[None]: ...
109109
def debug(self) -> None: ...
110110
if sys.version_info < (3, 11):

mypy/typeshed/stdlib/zipfile.pyi

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ _DateTuple: TypeAlias = tuple[int, int, int, int, int, int]
2929
_ReadWriteMode: TypeAlias = Literal["r", "w"]
3030
_ReadWriteBinaryMode: TypeAlias = Literal["r", "w", "rb", "wb"]
3131
_ZipFileMode: TypeAlias = Literal["r", "w", "x", "a"]
32+
_CompressionMode: TypeAlias = Literal[0, 8, 12, 14]
3233

3334
class BadZipFile(Exception): ...
3435

@@ -100,7 +101,7 @@ class ZipFile:
100101
fp: IO[bytes] | None
101102
NameToInfo: dict[str, ZipInfo]
102103
start_dir: int # undocumented
103-
compression: int # undocumented
104+
compression: _CompressionMode # undocumented
104105
compresslevel: int | None # undocumented
105106
mode: _ZipFileMode # undocumented
106107
pwd: bytes | None # undocumented
@@ -110,7 +111,7 @@ class ZipFile:
110111
self,
111112
file: StrPath | IO[bytes],
112113
mode: Literal["r"] = ...,
113-
compression: int = ...,
114+
compression: _CompressionMode = ...,
114115
allowZip64: bool = ...,
115116
compresslevel: int | None = ...,
116117
*,
@@ -122,7 +123,7 @@ class ZipFile:
122123
self,
123124
file: StrPath | IO[bytes],
124125
mode: _ZipFileMode = ...,
125-
compression: int = ...,
126+
compression: _CompressionMode = ...,
126127
allowZip64: bool = ...,
127128
compresslevel: int | None = ...,
128129
*,
@@ -134,7 +135,7 @@ class ZipFile:
134135
self,
135136
file: StrPath | IO[bytes],
136137
mode: _ZipFileMode = ...,
137-
compression: int = ...,
138+
compression: _CompressionMode = ...,
138139
allowZip64: bool = ...,
139140
compresslevel: int | None = ...,
140141
*,
@@ -145,7 +146,7 @@ class ZipFile:
145146
self,
146147
file: StrPath | IO[bytes],
147148
mode: _ZipFileMode = ...,
148-
compression: int = ...,
149+
compression: _CompressionMode = ...,
149150
allowZip64: bool = ...,
150151
compresslevel: int | None = ...,
151152
) -> None: ...
@@ -184,14 +185,19 @@ class ZipFile:
184185

185186
class PyZipFile(ZipFile):
186187
def __init__(
187-
self, file: str | IO[bytes], mode: _ZipFileMode = ..., compression: int = ..., allowZip64: bool = ..., optimize: int = ...
188+
self,
189+
file: str | IO[bytes],
190+
mode: _ZipFileMode = ...,
191+
compression: _CompressionMode = ...,
192+
allowZip64: bool = ...,
193+
optimize: int = ...,
188194
) -> None: ...
189195
def writepy(self, pathname: str, basename: str = ..., filterfunc: Callable[[str], bool] | None = ...) -> None: ...
190196

191197
class ZipInfo:
192198
filename: str
193199
date_time: _DateTuple
194-
compress_type: int
200+
compress_type: _CompressionMode
195201
comment: bytes
196202
extra: bytes
197203
create_system: int
@@ -269,10 +275,10 @@ if sys.version_info >= (3, 8):
269275

270276
def is_zipfile(filename: StrOrBytesPath | _SupportsReadSeekTell) -> bool: ...
271277

272-
ZIP_STORED: int
273-
ZIP_DEFLATED: int
278+
ZIP_STORED: Literal[0]
279+
ZIP_DEFLATED: Literal[8]
274280
ZIP64_LIMIT: int
275281
ZIP_FILECOUNT_LIMIT: int
276282
ZIP_MAX_COMMENT: int
277-
ZIP_BZIP2: int
278-
ZIP_LZMA: int
283+
ZIP_BZIP2: Literal[12]
284+
ZIP_LZMA: Literal[14]

0 commit comments

Comments
 (0)