Skip to content

Commit 772187f

Browse files
cdce8phauntsaninjaAlexWaygood
authored
Sync typeshed (#18880)
Source commit: python/typeshed@616ca7d This is the last typeshed commit with support for Python 3.8! --------- Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com> Co-authored-by: AlexWaygood <alex.waygood@gmail.com>
1 parent fcabf19 commit 772187f

File tree

18 files changed

+162
-95
lines changed

18 files changed

+162
-95
lines changed

mypy/stubgenc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,7 @@ def generate_property_stub(
765765

766766
def get_type_fullname(self, typ: type) -> str:
767767
"""Given a type, return a string representation"""
768-
if typ is Any: # type: ignore[comparison-overlap]
768+
if typ is Any:
769769
return "Any"
770770
typename = getattr(typ, "__qualname__", typ.__name__)
771771
module_name = self.get_obj_module(typ)

mypy/typeshed/stdlib/_typeshed/__init__.pyi

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# See the README.md file in this directory for more information.
44

55
import sys
6+
import typing_extensions
67
from collections.abc import Awaitable, Callable, Iterable, Sequence, Set as AbstractSet, Sized
78
from dataclasses import Field
89
from os import PathLike
@@ -328,9 +329,9 @@ class structseq(Generic[_T_co]):
328329
# The second parameter will accept a dict of any kind without raising an exception,
329330
# but only has any meaning if you supply it a dict where the keys are strings.
330331
# https://github.com/python/typeshed/pull/6560#discussion_r767149830
331-
def __new__(cls: type[Self], sequence: Iterable[_T_co], dict: dict[str, Any] = ...) -> Self: ...
332+
def __new__(cls, sequence: Iterable[_T_co], dict: dict[str, Any] = ...) -> typing_extensions.Self: ...
332333
if sys.version_info >= (3, 13):
333-
def __replace__(self: Self, **kwargs: Any) -> Self: ...
334+
def __replace__(self, **kwargs: Any) -> typing_extensions.Self: ...
334335

335336
# Superset of typing.AnyStr that also includes LiteralString
336337
AnyOrLiteralStr = TypeVar("AnyOrLiteralStr", str, bytes, LiteralString) # noqa: Y001

mypy/typeshed/stdlib/asyncio/sslproto.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class _SSLProtocolTransport(transports._FlowControlMixin, transports.Transport):
7676
def get_extra_info(self, name: str, default: Any | None = None) -> dict[str, Any]: ...
7777
@property
7878
def _protocol_paused(self) -> bool: ...
79-
def write(self, data: bytes | bytearray | memoryview) -> None: ...
79+
def write(self, data: bytes | bytearray | memoryview[Any]) -> None: ... # any memoryview format or shape
8080
def can_write_eof(self) -> Literal[False]: ...
8181
if sys.version_info >= (3, 11):
8282
def get_write_buffer_limits(self) -> tuple[int, int]: ...

mypy/typeshed/stdlib/asyncio/transports.pyi

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ class WriteTransport(BaseTransport):
2424
def set_write_buffer_limits(self, high: int | None = None, low: int | None = None) -> None: ...
2525
def get_write_buffer_size(self) -> int: ...
2626
def get_write_buffer_limits(self) -> tuple[int, int]: ...
27-
def write(self, data: bytes | bytearray | memoryview) -> None: ...
28-
def writelines(self, list_of_data: Iterable[bytes | bytearray | memoryview]) -> None: ...
27+
def write(self, data: bytes | bytearray | memoryview[Any]) -> None: ... # any memoryview format or shape
28+
def writelines(
29+
self, list_of_data: Iterable[bytes | bytearray | memoryview[Any]]
30+
) -> None: ... # any memoryview format or shape
2931
def write_eof(self) -> None: ...
3032
def can_write_eof(self) -> bool: ...
3133
def abort(self) -> None: ...

mypy/typeshed/stdlib/heapq.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from _heapq import *
22
from _typeshed import SupportsRichComparison
3-
from collections.abc import Callable, Iterable
3+
from collections.abc import Callable, Generator, Iterable
44
from typing import Any, Final, TypeVar
55

66
__all__ = ["heappush", "heappop", "heapify", "heapreplace", "merge", "nlargest", "nsmallest", "heappushpop"]
@@ -11,7 +11,7 @@ __about__: Final[str]
1111

1212
def merge(
1313
*iterables: Iterable[_S], key: Callable[[_S], SupportsRichComparison] | None = None, reverse: bool = False
14-
) -> Iterable[_S]: ...
14+
) -> Generator[_S]: ...
1515
def nlargest(n: int, iterable: Iterable[_S], key: Callable[[_S], SupportsRichComparison] | None = None) -> list[_S]: ...
1616
def nsmallest(n: int, iterable: Iterable[_S], key: Callable[[_S], SupportsRichComparison] | None = None) -> list[_S]: ...
1717
def _heapify_max(heap: list[Any], /) -> None: ... # undocumented

mypy/typeshed/stdlib/http/server.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import sys
66
from _typeshed import StrPath, SupportsRead, SupportsWrite
77
from collections.abc import Mapping, Sequence
88
from typing import Any, AnyStr, BinaryIO, ClassVar
9+
from typing_extensions import deprecated
910

1011
__all__ = ["HTTPServer", "ThreadingHTTPServer", "BaseHTTPRequestHandler", "SimpleHTTPRequestHandler", "CGIHTTPRequestHandler"]
1112

@@ -72,7 +73,7 @@ class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
7273
def guess_type(self, path: StrPath) -> str: ... # undocumented
7374

7475
def executable(path: StrPath) -> bool: ... # undocumented
75-
76+
@deprecated("Deprecated in Python 3.13; removal scheduled for Python 3.15")
7677
class CGIHTTPRequestHandler(SimpleHTTPRequestHandler):
7778
cgi_directories: list[str]
7879
have_fork: bool # undocumented

mypy/typeshed/stdlib/importlib/resources/__init__.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ from collections.abc import Iterator
44
from contextlib import AbstractContextManager
55
from pathlib import Path
66
from types import ModuleType
7-
from typing import Any, BinaryIO, TextIO
7+
from typing import Any, BinaryIO, Literal, TextIO
88
from typing_extensions import TypeAlias
99

1010
if sys.version_info >= (3, 11):
@@ -51,14 +51,14 @@ else:
5151
def open_text(package: Package, resource: Resource, encoding: str = "utf-8", errors: str = "strict") -> TextIO: ...
5252
def read_binary(package: Package, resource: Resource) -> bytes: ...
5353
def read_text(package: Package, resource: Resource, encoding: str = "utf-8", errors: str = "strict") -> str: ...
54-
def path(package: Package, resource: Resource) -> AbstractContextManager[Path]: ...
54+
def path(package: Package, resource: Resource) -> AbstractContextManager[Path, Literal[False]]: ...
5555
def is_resource(package: Package, name: str) -> bool: ...
5656
def contents(package: Package) -> Iterator[str]: ...
5757

5858
if sys.version_info >= (3, 11):
5959
from importlib.resources._common import as_file as as_file
6060
elif sys.version_info >= (3, 9):
61-
def as_file(path: Traversable) -> AbstractContextManager[Path]: ...
61+
def as_file(path: Traversable) -> AbstractContextManager[Path, Literal[False]]: ...
6262

6363
if sys.version_info >= (3, 11):
6464
from importlib.resources._common import files as files

mypy/typeshed/stdlib/importlib/resources/_common.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ if sys.version_info >= (3, 11):
77
from contextlib import AbstractContextManager
88
from importlib.abc import ResourceReader, Traversable
99
from pathlib import Path
10-
from typing import overload
10+
from typing import Literal, overload
1111
from typing_extensions import TypeAlias, deprecated
1212

1313
Package: TypeAlias = str | types.ModuleType
@@ -39,4 +39,4 @@ if sys.version_info >= (3, 11):
3939
def get_package(package: Package) -> types.ModuleType: ...
4040

4141
def from_package(package: types.ModuleType) -> Traversable: ...
42-
def as_file(path: Traversable) -> AbstractContextManager[Path]: ...
42+
def as_file(path: Traversable) -> AbstractContextManager[Path, Literal[False]]: ...

mypy/typeshed/stdlib/importlib/resources/_functional.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ if sys.version_info >= (3, 13):
88
from importlib.resources._common import Anchor
99
from io import TextIOWrapper
1010
from pathlib import Path
11-
from typing import BinaryIO, overload
11+
from typing import BinaryIO, Literal, overload
1212
from typing_extensions import Unpack
1313

1414
def open_binary(anchor: Anchor, *path_names: StrPath) -> BinaryIO: ...
@@ -25,6 +25,6 @@ if sys.version_info >= (3, 13):
2525
) -> str: ...
2626
@overload
2727
def read_text(anchor: Anchor, *path_names: StrPath, encoding: str | None, errors: str | None = "strict") -> str: ...
28-
def path(anchor: Anchor, *path_names: StrPath) -> AbstractContextManager[Path]: ...
28+
def path(anchor: Anchor, *path_names: StrPath) -> AbstractContextManager[Path, Literal[False]]: ...
2929
def is_resource(anchor: Anchor, *path_names: StrPath) -> bool: ...
3030
def contents(anchor: Anchor, *path_names: StrPath) -> Iterator[str]: ...

mypy/typeshed/stdlib/inspect.pyi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -345,12 +345,12 @@ class Signature:
345345

346346
if sys.version_info >= (3, 10):
347347
def get_annotations(
348-
obj: Callable[..., object] | type[Any] | ModuleType,
348+
obj: Callable[..., object] | type[object] | ModuleType, # any callable, class, or module
349349
*,
350-
globals: Mapping[str, Any] | None = None,
351-
locals: Mapping[str, Any] | None = None,
350+
globals: Mapping[str, Any] | None = None, # value types depend on the key
351+
locals: Mapping[str, Any] | None = None, # value types depend on the key
352352
eval_str: bool = False,
353-
) -> dict[str, Any]: ...
353+
) -> dict[str, Any]: ... # values are type expressions
354354

355355
# The name is the same as the enum's name in CPython
356356
class _ParameterKind(enum.IntEnum):

0 commit comments

Comments
 (0)