Skip to content

Commit 9286425

Browse files
authored
Sync typeshed (#20241)
Source commit: python/typeshed@ebce8d7
1 parent 8e2ce96 commit 9286425

File tree

23 files changed

+251
-67
lines changed

23 files changed

+251
-67
lines changed

mypy/typeshed/stdlib/_compression.pyi

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# _compression is replaced by compression._common._streams on Python 3.14+ (PEP-784)
22

3-
from _typeshed import Incomplete, WriteableBuffer
3+
from _typeshed import ReadableBuffer, WriteableBuffer
44
from collections.abc import Callable
55
from io import DEFAULT_BUFFER_SIZE, BufferedIOBase, RawIOBase
66
from typing import Any, Protocol, type_check_only
@@ -13,13 +13,24 @@ class _Reader(Protocol):
1313
def seekable(self) -> bool: ...
1414
def seek(self, n: int, /) -> Any: ...
1515

16+
@type_check_only
17+
class _Decompressor(Protocol):
18+
def decompress(self, data: ReadableBuffer, /, max_length: int = ...) -> bytes: ...
19+
@property
20+
def unused_data(self) -> bytes: ...
21+
@property
22+
def eof(self) -> bool: ...
23+
# `zlib._Decompress` does not have next property, but `DecompressReader` calls it:
24+
# @property
25+
# def needs_input(self) -> bool: ...
26+
1627
class BaseStream(BufferedIOBase): ...
1728

1829
class DecompressReader(RawIOBase):
1930
def __init__(
2031
self,
2132
fp: _Reader,
22-
decomp_factory: Callable[..., Incomplete],
33+
decomp_factory: Callable[..., _Decompressor],
2334
trailing_error: type[Exception] | tuple[type[Exception], ...] = (),
2435
**decomp_args: Any, # These are passed to decomp_factory.
2536
) -> None: ...

mypy/typeshed/stdlib/asyncio/protocols.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class BaseProtocol:
1414

1515
class Protocol(BaseProtocol):
1616
# Need annotation or mypy will complain about 'Cannot determine type of "__slots__" in base class'
17-
__slots__: tuple[()] = ()
17+
__slots__: tuple[str, ...] = ()
1818
def data_received(self, data: bytes) -> None: ...
1919
def eof_received(self) -> bool | None: ...
2020

@@ -35,7 +35,7 @@ class DatagramProtocol(BaseProtocol):
3535
def error_received(self, exc: Exception) -> None: ...
3636

3737
class SubprocessProtocol(BaseProtocol):
38-
__slots__: tuple[()] = ()
38+
__slots__: tuple[str, ...] = ()
3939
def pipe_data_received(self, fd: int, data: bytes) -> None: ...
4040
def pipe_connection_lost(self, fd: int, exc: Exception | None) -> None: ...
4141
def process_exited(self) -> None: ...

mypy/typeshed/stdlib/builtins.pyi

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ from typing import ( # noqa: Y022,UP035
4242
Any,
4343
BinaryIO,
4444
ClassVar,
45+
Final,
4546
Generic,
4647
Mapping,
4748
MutableMapping,
@@ -188,8 +189,9 @@ class type:
188189
__bases__: tuple[type, ...]
189190
@property
190191
def __basicsize__(self) -> int: ...
191-
@property
192-
def __dict__(self) -> types.MappingProxyType[str, Any]: ... # type: ignore[override]
192+
# type.__dict__ is read-only at runtime, but that can't be expressed currently.
193+
# See https://github.com/python/typeshed/issues/11033 for a discussion.
194+
__dict__: Final[types.MappingProxyType[str, Any]] # type: ignore[assignment]
193195
@property
194196
def __dictoffset__(self) -> int: ...
195197
@property
@@ -1267,13 +1269,6 @@ class property:
12671269
def __set__(self, instance: Any, value: Any, /) -> None: ...
12681270
def __delete__(self, instance: Any, /) -> None: ...
12691271

1270-
@final
1271-
@type_check_only
1272-
class _NotImplementedType(Any):
1273-
__call__: None
1274-
1275-
NotImplemented: _NotImplementedType
1276-
12771272
def abs(x: SupportsAbs[_T], /) -> _T: ...
12781273
def all(iterable: Iterable[object], /) -> bool: ...
12791274
def any(iterable: Iterable[object], /) -> bool: ...
@@ -1932,14 +1927,14 @@ def __import__(
19321927
def __build_class__(func: Callable[[], CellType | Any], name: str, /, *bases: Any, metaclass: Any = ..., **kwds: Any) -> Any: ...
19331928

19341929
if sys.version_info >= (3, 10):
1935-
from types import EllipsisType
1930+
from types import EllipsisType, NotImplementedType
19361931

19371932
# Backwards compatibility hack for folks who relied on the ellipsis type
19381933
# existing in typeshed in Python 3.9 and earlier.
19391934
ellipsis = EllipsisType
19401935

19411936
Ellipsis: EllipsisType
1942-
1937+
NotImplemented: NotImplementedType
19431938
else:
19441939
# Actually the type of Ellipsis is <type 'ellipsis'>, but since it's
19451940
# not exposed anywhere under that name, we make it private here.
@@ -1949,6 +1944,12 @@ else:
19491944

19501945
Ellipsis: ellipsis
19511946

1947+
@final
1948+
@type_check_only
1949+
class _NotImplementedType(Any): ...
1950+
1951+
NotImplemented: _NotImplementedType
1952+
19521953
@disjoint_base
19531954
class BaseException:
19541955
args: tuple[Any, ...]

mypy/typeshed/stdlib/compression/_common/_streams.pyi

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from _typeshed import Incomplete, WriteableBuffer
1+
from _typeshed import ReadableBuffer, WriteableBuffer
22
from collections.abc import Callable
33
from io import DEFAULT_BUFFER_SIZE, BufferedIOBase, RawIOBase
44
from typing import Any, Protocol, type_check_only
@@ -11,13 +11,24 @@ class _Reader(Protocol):
1111
def seekable(self) -> bool: ...
1212
def seek(self, n: int, /) -> Any: ...
1313

14+
@type_check_only
15+
class _Decompressor(Protocol):
16+
def decompress(self, data: ReadableBuffer, /, max_length: int = ...) -> bytes: ...
17+
@property
18+
def unused_data(self) -> bytes: ...
19+
@property
20+
def eof(self) -> bool: ...
21+
# `zlib._Decompress` does not have next property, but `DecompressReader` calls it:
22+
# @property
23+
# def needs_input(self) -> bool: ...
24+
1425
class BaseStream(BufferedIOBase): ...
1526

1627
class DecompressReader(RawIOBase):
1728
def __init__(
1829
self,
1930
fp: _Reader,
20-
decomp_factory: Callable[..., Incomplete], # Consider backporting changes to _compression
31+
decomp_factory: Callable[..., _Decompressor], # Consider backporting changes to _compression
2132
trailing_error: type[Exception] | tuple[type[Exception], ...] = (),
2233
**decomp_args: Any, # These are passed to decomp_factory.
2334
) -> None: ...

mypy/typeshed/stdlib/html/parser.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ class HTMLParser(ParserBase):
99
# Added in Python 3.9.23, 3.10.18, 3.11.13, 3.12.11, 3.13.6
1010
RCDATA_CONTENT_ELEMENTS: Final[tuple[str, ...]]
1111

12-
def __init__(self, *, convert_charrefs: bool = True) -> None: ...
12+
# `scripting` parameter added in Python 3.9.25, 3.10.20, 3.11.15, 3.12.13, 3.13.10, 3.14.1
13+
def __init__(self, *, convert_charrefs: bool = True, scripting: bool = False) -> None: ...
1314
def feed(self, data: str) -> None: ...
1415
def close(self) -> None: ...
1516
def get_starttag_text(self) -> str | None: ...

mypy/typeshed/stdlib/http/client.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ class HTTPResponse(io.BufferedIOBase, BinaryIO): # type: ignore[misc] # incomp
166166
def begin(self) -> None: ...
167167

168168
class HTTPConnection:
169+
blocksize: int
169170
auto_open: int # undocumented
170171
debuglevel: int
171172
default_port: int # undocumented

mypy/typeshed/stdlib/imaplib.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class IMAP4:
2626
class error(Exception): ...
2727
class abort(error): ...
2828
class readonly(abort): ...
29+
utf8_enabled: bool
2930
mustquote: Pattern[str]
3031
debug: int
3132
state: str

mypy/typeshed/stdlib/importlib/util.pyi

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ from importlib._bootstrap_external import (
1212
spec_from_file_location as spec_from_file_location,
1313
)
1414
from importlib.abc import Loader
15-
from typing_extensions import ParamSpec, deprecated
15+
from types import TracebackType
16+
from typing import Literal
17+
from typing_extensions import ParamSpec, Self, deprecated
1618

1719
_P = ParamSpec("_P")
1820

@@ -44,6 +46,18 @@ class LazyLoader(Loader):
4446

4547
def source_hash(source_bytes: ReadableBuffer) -> bytes: ...
4648

49+
if sys.version_info >= (3, 12):
50+
class _incompatible_extension_module_restrictions:
51+
def __init__(self, *, disable_check: bool) -> None: ...
52+
disable_check: bool
53+
old: Literal[-1, 0, 1] # exists only while entered
54+
def __enter__(self) -> Self: ...
55+
def __exit__(
56+
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
57+
) -> None: ...
58+
@property
59+
def override(self) -> Literal[-1, 1]: ... # undocumented
60+
4761
if sys.version_info >= (3, 14):
4862
__all__ = [
4963
"LazyLoader",

mypy/typeshed/stdlib/locale.pyi

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@ if sys.version_info < (3, 12):
153153
def format_string(f: _str, val: Any, grouping: bool = False, monetary: bool = False) -> _str: ...
154154
def currency(val: float | Decimal, symbol: bool = True, grouping: bool = False, international: bool = False) -> _str: ...
155155
def delocalize(string: _str) -> _str: ...
156+
157+
if sys.version_info >= (3, 10):
158+
def localize(string: _str, grouping: bool = False, monetary: bool = False) -> _str: ...
159+
156160
def atof(string: _str, func: Callable[[_str], float] = ...) -> float: ...
157161
def atoi(string: _str) -> int: ...
158162
def str(val: float) -> _str: ...

mypy/typeshed/stdlib/os/__init__.pyi

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,22 @@ from typing import (
4141
runtime_checkable,
4242
type_check_only,
4343
)
44-
from typing_extensions import Self, TypeAlias, Unpack, deprecated
44+
from typing_extensions import LiteralString, Self, TypeAlias, Unpack, deprecated
4545

4646
from . import path as _path
4747

48+
# Re-export common definitions from os.path to reduce duplication
49+
from .path import (
50+
altsep as altsep,
51+
curdir as curdir,
52+
defpath as defpath,
53+
devnull as devnull,
54+
extsep as extsep,
55+
pardir as pardir,
56+
pathsep as pathsep,
57+
sep as sep,
58+
)
59+
4860
__all__ = [
4961
"F_OK",
5062
"O_APPEND",
@@ -674,19 +686,8 @@ if sys.platform != "win32":
674686
ST_NOSUID: Final[int]
675687
ST_RDONLY: Final[int]
676688

677-
curdir: str
678-
pardir: str
679-
sep: str
680-
if sys.platform == "win32":
681-
altsep: str
682-
else:
683-
altsep: str | None
684-
extsep: str
685-
pathsep: str
686-
defpath: str
687689
linesep: Literal["\n", "\r\n"]
688-
devnull: str
689-
name: str
690+
name: LiteralString
690691

691692
F_OK: Final = 0
692693
R_OK: Final = 4

0 commit comments

Comments
 (0)