Sync vendored typeshed stubs (#11428)

Co-authored-by: typeshedbot <>
This commit is contained in:
github-actions[bot] 2024-05-15 00:46:41 +00:00 committed by GitHub
parent bdc15a7cb9
commit effe3ad4ef
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 132 additions and 71 deletions

View file

@ -1 +1 @@
2d33fe212221a05661c0db5215a91cf3d7b7f072 a9d7e861f7a46ae7acd56569326adef302e10f29

View file

@ -0,0 +1,18 @@
# Implicit protocols used in importlib.
# We intentionally omit deprecated and optional methods.
from collections.abc import Sequence
from importlib.machinery import ModuleSpec
from types import ModuleType
from typing import Protocol
__all__ = ["LoaderProtocol", "MetaPathFinderProtocol", "PathEntryFinderProtocol"]
class LoaderProtocol(Protocol):
def load_module(self, fullname: str, /) -> ModuleType: ...
class MetaPathFinderProtocol(Protocol):
def find_spec(self, fullname: str, path: Sequence[str] | None, target: ModuleType | None = ..., /) -> ModuleSpec | None: ...
class PathEntryFinderProtocol(Protocol):
def find_spec(self, fullname: str, target: ModuleType | None = ..., /) -> ModuleSpec | None: ...

View file

@ -31,7 +31,7 @@ from _typeshed import (
) )
from collections.abc import Awaitable, Callable, Iterable, Iterator, MutableSet, Reversible, Set as AbstractSet, Sized from collections.abc import Awaitable, Callable, Iterable, Iterator, MutableSet, Reversible, Set as AbstractSet, Sized
from io import BufferedRandom, BufferedReader, BufferedWriter, FileIO, TextIOWrapper from io import BufferedRandom, BufferedReader, BufferedWriter, FileIO, TextIOWrapper
from types import CodeType, TracebackType, _Cell from types import CellType, CodeType, TracebackType
# mypy crashes if any of {ByteString, Sequence, MutableSequence, Mapping, MutableMapping} are imported from collections.abc in builtins.pyi # mypy crashes if any of {ByteString, Sequence, MutableSequence, Mapping, MutableMapping} are imported from collections.abc in builtins.pyi
from typing import ( # noqa: Y022 from typing import ( # noqa: Y022
@ -951,7 +951,7 @@ class tuple(Sequence[_T_co]):
class function: class function:
# Make sure this class definition stays roughly in line with `types.FunctionType` # Make sure this class definition stays roughly in line with `types.FunctionType`
@property @property
def __closure__(self) -> tuple[_Cell, ...] | None: ... def __closure__(self) -> tuple[CellType, ...] | None: ...
__code__: CodeType __code__: CodeType
__defaults__: tuple[Any, ...] | None __defaults__: tuple[Any, ...] | None
__dict__: dict[str, Any] __dict__: dict[str, Any]
@ -1333,7 +1333,7 @@ if sys.version_info >= (3, 11):
locals: Mapping[str, object] | None = None, locals: Mapping[str, object] | None = None,
/, /,
*, *,
closure: tuple[_Cell, ...] | None = None, closure: tuple[CellType, ...] | None = None,
) -> None: ... ) -> None: ...
else: else:
@ -1794,7 +1794,7 @@ def __import__(
fromlist: Sequence[str] = (), fromlist: Sequence[str] = (),
level: int = 0, level: int = 0,
) -> types.ModuleType: ... ) -> types.ModuleType: ...
def __build_class__(func: Callable[[], _Cell | Any], name: str, /, *bases: Any, metaclass: Any = ..., **kwds: Any) -> Any: ... def __build_class__(func: Callable[[], CellType | Any], name: str, /, *bases: Any, metaclass: Any = ..., **kwds: Any) -> Any: ...
if sys.version_info >= (3, 10): if sys.version_info >= (3, 10):
from types import EllipsisType from types import EllipsisType

View file

@ -1,3 +1,5 @@
import sys
from _typeshed import StrOrBytesPath
from collections.abc import Iterator, MutableMapping from collections.abc import Iterator, MutableMapping
from types import TracebackType from types import TracebackType
from typing import Literal from typing import Literal
@ -91,5 +93,10 @@ class _error(Exception): ...
error: tuple[type[_error], type[OSError]] error: tuple[type[_error], type[OSError]]
if sys.version_info >= (3, 11):
def whichdb(filename: StrOrBytesPath) -> str | None: ...
def open(file: StrOrBytesPath, flag: _TFlags = "r", mode: int = 0o666) -> _Database: ...
else:
def whichdb(filename: str) -> str | None: ... def whichdb(filename: str) -> str | None: ...
def open(file: str, flag: _TFlags = "r", mode: int = 0o666) -> _Database: ... def open(file: str, flag: _TFlags = "r", mode: int = 0o666) -> _Database: ...

View file

@ -1,3 +1,5 @@
import sys
from _typeshed import StrOrBytesPath
from collections.abc import Iterator, MutableMapping from collections.abc import Iterator, MutableMapping
from types import TracebackType from types import TracebackType
from typing_extensions import Self, TypeAlias from typing_extensions import Self, TypeAlias
@ -28,4 +30,8 @@ class _Database(MutableMapping[_KeyType, bytes]):
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
) -> None: ... ) -> None: ...
if sys.version_info >= (3, 11):
def open(file: StrOrBytesPath, flag: str = "c", mode: int = 0o666) -> _Database: ...
else:
def open(file: str, flag: str = "c", mode: int = 0o666) -> _Database: ... def open(file: str, flag: str = "c", mode: int = 0o666) -> _Database: ...

View file

@ -1,5 +1,5 @@
import sys import sys
from _typeshed import ReadOnlyBuffer from _typeshed import ReadOnlyBuffer, StrOrBytesPath
from types import TracebackType from types import TracebackType
from typing import TypeVar, overload from typing import TypeVar, overload
from typing_extensions import Self, TypeAlias from typing_extensions import Self, TypeAlias
@ -38,4 +38,7 @@ if sys.platform != "win32":
__new__: None # type: ignore[assignment] __new__: None # type: ignore[assignment]
__init__: None # type: ignore[assignment] __init__: None # type: ignore[assignment]
if sys.version_info >= (3, 11):
def open(filename: StrOrBytesPath, flags: str = "r", mode: int = 0o666, /) -> _gdbm: ...
else:
def open(filename: str, flags: str = "r", mode: int = 0o666, /) -> _gdbm: ... def open(filename: str, flags: str = "r", mode: int = 0o666, /) -> _gdbm: ...

View file

@ -1,5 +1,5 @@
import sys import sys
from _typeshed import ReadOnlyBuffer from _typeshed import ReadOnlyBuffer, StrOrBytesPath
from types import TracebackType from types import TracebackType
from typing import TypeVar, overload from typing import TypeVar, overload
from typing_extensions import Self, TypeAlias from typing_extensions import Self, TypeAlias
@ -34,4 +34,7 @@ if sys.platform != "win32":
__new__: None # type: ignore[assignment] __new__: None # type: ignore[assignment]
__init__: None # type: ignore[assignment] __init__: None # type: ignore[assignment]
if sys.version_info >= (3, 11):
def open(filename: StrOrBytesPath, flags: str = "r", mode: int = 0o666, /) -> _dbm: ...
else:
def open(filename: str, flags: str = "r", mode: int = 0o666, /) -> _dbm: ... def open(filename: str, flags: str = "r", mode: int = 0o666, /) -> _dbm: ...

View file

@ -64,7 +64,7 @@ class SourceLoader(ResourceLoader, ExecutionLoader, metaclass=ABCMeta):
# The base classes differ starting in 3.10: # The base classes differ starting in 3.10:
if sys.version_info >= (3, 10): if sys.version_info >= (3, 10):
# Please keep in sync with sys._MetaPathFinder # Please keep in sync with _typeshed.importlib.MetaPathFinderProtocol
class MetaPathFinder(metaclass=ABCMeta): class MetaPathFinder(metaclass=ABCMeta):
if sys.version_info < (3, 12): if sys.version_info < (3, 12):
def find_module(self, fullname: str, path: Sequence[str] | None) -> Loader | None: ... def find_module(self, fullname: str, path: Sequence[str] | None) -> Loader | None: ...
@ -85,7 +85,7 @@ if sys.version_info >= (3, 10):
def find_spec(self, fullname: str, target: types.ModuleType | None = ...) -> ModuleSpec | None: ... def find_spec(self, fullname: str, target: types.ModuleType | None = ...) -> ModuleSpec | None: ...
else: else:
# Please keep in sync with sys._MetaPathFinder # Please keep in sync with _typeshed.importlib.MetaPathFinderProtocol
class MetaPathFinder(Finder): class MetaPathFinder(Finder):
def find_module(self, fullname: str, path: Sequence[str] | None) -> Loader | None: ... def find_module(self, fullname: str, path: Sequence[str] | None) -> Loader | None: ...
def invalidate_caches(self) -> None: ... def invalidate_caches(self) -> None: ...

View file

@ -3,6 +3,7 @@ import importlib.machinery
import sys import sys
import types import types
from _typeshed import ReadableBuffer, StrOrBytesPath from _typeshed import ReadableBuffer, StrOrBytesPath
from _typeshed.importlib import LoaderProtocol
from collections.abc import Callable from collections.abc import Callable
from typing import Any from typing import Any
from typing_extensions import ParamSpec from typing_extensions import ParamSpec
@ -23,13 +24,13 @@ def source_from_cache(path: str) -> str: ...
def decode_source(source_bytes: ReadableBuffer) -> str: ... def decode_source(source_bytes: ReadableBuffer) -> str: ...
def find_spec(name: str, package: str | None = None) -> importlib.machinery.ModuleSpec | None: ... def find_spec(name: str, package: str | None = None) -> importlib.machinery.ModuleSpec | None: ...
def spec_from_loader( def spec_from_loader(
name: str, loader: importlib.abc.Loader | None, *, origin: str | None = None, is_package: bool | None = None name: str, loader: LoaderProtocol | None, *, origin: str | None = None, is_package: bool | None = None
) -> importlib.machinery.ModuleSpec | None: ... ) -> importlib.machinery.ModuleSpec | None: ...
def spec_from_file_location( def spec_from_file_location(
name: str, name: str,
location: StrOrBytesPath | None = None, location: StrOrBytesPath | None = None,
*, *,
loader: importlib.abc.Loader | None = None, loader: LoaderProtocol | None = None,
submodule_search_locations: list[str] | None = ..., submodule_search_locations: list[str] | None = ...,
) -> importlib.machinery.ModuleSpec | None: ... ) -> importlib.machinery.ModuleSpec | None: ...
def module_from_spec(spec: importlib.machinery.ModuleSpec) -> types.ModuleType: ... def module_from_spec(spec: importlib.machinery.ModuleSpec) -> types.ModuleType: ...

View file

@ -1,7 +1,7 @@
import sys import sys
from _typeshed import SupportsRead from _typeshed import SupportsRead
from _typeshed.importlib import LoaderProtocol, MetaPathFinderProtocol, PathEntryFinderProtocol
from collections.abc import Callable, Iterable, Iterator from collections.abc import Callable, Iterable, Iterator
from importlib.abc import Loader, MetaPathFinder, PathEntryFinder
from typing import IO, Any, NamedTuple, TypeVar from typing import IO, Any, NamedTuple, TypeVar
from typing_extensions import deprecated from typing_extensions import deprecated
@ -23,7 +23,7 @@ if sys.version_info < (3, 12):
_PathT = TypeVar("_PathT", bound=Iterable[str]) _PathT = TypeVar("_PathT", bound=Iterable[str])
class ModuleInfo(NamedTuple): class ModuleInfo(NamedTuple):
module_finder: MetaPathFinder | PathEntryFinder module_finder: MetaPathFinderProtocol | PathEntryFinderProtocol
name: str name: str
ispkg: bool ispkg: bool
@ -37,11 +37,11 @@ if sys.version_info < (3, 12):
def __init__(self, fullname: str, file: IO[str], filename: str, etc: tuple[str, str, int]) -> None: ... def __init__(self, fullname: str, file: IO[str], filename: str, etc: tuple[str, str, int]) -> None: ...
@deprecated("Use importlib.util.find_spec() instead. Will be removed in Python 3.14.") @deprecated("Use importlib.util.find_spec() instead. Will be removed in Python 3.14.")
def find_loader(fullname: str) -> Loader | None: ... def find_loader(fullname: str) -> LoaderProtocol | None: ...
def get_importer(path_item: str) -> PathEntryFinder | None: ... def get_importer(path_item: str) -> PathEntryFinderProtocol | None: ...
@deprecated("Use importlib.util.find_spec() instead. Will be removed in Python 3.14.") @deprecated("Use importlib.util.find_spec() instead. Will be removed in Python 3.14.")
def get_loader(module_or_name: str) -> Loader | None: ... def get_loader(module_or_name: str) -> LoaderProtocol | None: ...
def iter_importers(fullname: str = "") -> Iterator[MetaPathFinder | PathEntryFinder]: ... def iter_importers(fullname: str = "") -> Iterator[MetaPathFinderProtocol | PathEntryFinderProtocol]: ...
def iter_modules(path: Iterable[str] | None = None, prefix: str = "") -> Iterator[ModuleInfo]: ... def iter_modules(path: Iterable[str] | None = None, prefix: str = "") -> Iterator[ModuleInfo]: ...
def read_code(stream: SupportsRead[bytes]) -> Any: ... # undocumented def read_code(stream: SupportsRead[bytes]) -> Any: ... # undocumented
def walk_packages( def walk_packages(

View file

@ -1,3 +1,5 @@
import sys
from _typeshed import StrOrBytesPath
from collections.abc import Iterator, MutableMapping from collections.abc import Iterator, MutableMapping
from dbm import _TFlags from dbm import _TFlags
from types import TracebackType from types import TracebackType
@ -41,6 +43,17 @@ class BsdDbShelf(Shelf[_VT]):
def last(self) -> tuple[str, _VT]: ... def last(self) -> tuple[str, _VT]: ...
class DbfilenameShelf(Shelf[_VT]): class DbfilenameShelf(Shelf[_VT]):
if sys.version_info >= (3, 11):
def __init__(
self, filename: StrOrBytesPath, flag: _TFlags = "c", protocol: int | None = None, writeback: bool = False
) -> None: ...
else:
def __init__(self, filename: str, flag: _TFlags = "c", protocol: int | None = None, writeback: bool = False) -> None: ... def __init__(self, filename: str, flag: _TFlags = "c", protocol: int | None = None, writeback: bool = False) -> None: ...
if sys.version_info >= (3, 11):
def open(
filename: StrOrBytesPath, flag: _TFlags = "c", protocol: int | None = None, writeback: bool = False
) -> Shelf[Any]: ...
else:
def open(filename: str, flag: _TFlags = "c", protocol: int | None = None, writeback: bool = False) -> Shelf[Any]: ... def open(filename: str, flag: _TFlags = "c", protocol: int | None = None, writeback: bool = False) -> Shelf[Any]: ...

View file

@ -474,6 +474,13 @@ if sys.version_info >= (3, 12):
ETHERTYPE_VLAN as ETHERTYPE_VLAN, ETHERTYPE_VLAN as ETHERTYPE_VLAN,
) )
if sys.platform == "linux":
from _socket import ETH_P_ALL as ETH_P_ALL
if sys.platform != "linux" and sys.platform != "win32" and sys.platform != "darwin":
# FreeBSD >= 14.0
from _socket import PF_DIVERT as PF_DIVERT
# Re-exported from errno # Re-exported from errno
EBADF: int EBADF: int
EAGAIN: int EAGAIN: int
@ -525,6 +532,9 @@ class AddressFamily(IntEnum):
AF_BLUETOOTH = 32 AF_BLUETOOTH = 32
if sys.platform == "win32" and sys.version_info >= (3, 12): if sys.platform == "win32" and sys.version_info >= (3, 12):
AF_HYPERV = 34 AF_HYPERV = 34
if sys.platform != "linux" and sys.platform != "win32" and sys.platform != "darwin" and sys.version_info >= (3, 12):
# FreeBSD >= 14.0
AF_DIVERT = 44
AF_INET = AddressFamily.AF_INET AF_INET = AddressFamily.AF_INET
AF_INET6 = AddressFamily.AF_INET6 AF_INET6 = AddressFamily.AF_INET6
@ -577,6 +587,9 @@ if sys.platform != "win32" or sys.version_info >= (3, 9):
if sys.platform == "win32" and sys.version_info >= (3, 12): if sys.platform == "win32" and sys.version_info >= (3, 12):
AF_HYPERV = AddressFamily.AF_HYPERV AF_HYPERV = AddressFamily.AF_HYPERV
if sys.platform != "linux" and sys.platform != "win32" and sys.platform != "darwin" and sys.version_info >= (3, 12):
# FreeBSD >= 14.0
AF_DIVERT = AddressFamily.AF_DIVERT
class SocketKind(IntEnum): class SocketKind(IntEnum):
SOCK_STREAM = 1 SOCK_STREAM = 1

View file

@ -1,9 +1,8 @@
import sys import sys
from _typeshed import OptExcInfo, ProfileFunction, TraceFunction, structseq from _typeshed import OptExcInfo, ProfileFunction, TraceFunction, structseq
from _typeshed.importlib import MetaPathFinderProtocol, PathEntryFinderProtocol
from builtins import object as _object from builtins import object as _object
from collections.abc import AsyncGenerator, Callable, Sequence from collections.abc import AsyncGenerator, Callable, Sequence
from importlib.abc import PathEntryFinder
from importlib.machinery import ModuleSpec
from io import TextIOWrapper from io import TextIOWrapper
from types import FrameType, ModuleType, TracebackType from types import FrameType, ModuleType, TracebackType
from typing import Any, Final, Literal, NoReturn, Protocol, TextIO, TypeVar, final from typing import Any, Final, Literal, NoReturn, Protocol, TextIO, TypeVar, final
@ -15,10 +14,6 @@ _T = TypeVar("_T")
_ExitCode: TypeAlias = str | int | None _ExitCode: TypeAlias = str | int | None
_OptExcInfo: TypeAlias = OptExcInfo # noqa: Y047 # TODO: obsolete, remove fall 2022 or later _OptExcInfo: TypeAlias = OptExcInfo # noqa: Y047 # TODO: obsolete, remove fall 2022 or later
# Intentionally omits one deprecated and one optional method of `importlib.abc.MetaPathFinder`
class _MetaPathFinder(Protocol):
def find_spec(self, fullname: str, path: Sequence[str] | None, target: ModuleType | None = ..., /) -> ModuleSpec | None: ...
# ----- sys variables ----- # ----- sys variables -----
if sys.platform != "win32": if sys.platform != "win32":
abiflags: str abiflags: str
@ -44,13 +39,13 @@ if sys.version_info >= (3, 12):
last_exc: BaseException # or undefined. last_exc: BaseException # or undefined.
maxsize: int maxsize: int
maxunicode: int maxunicode: int
meta_path: list[_MetaPathFinder] meta_path: list[MetaPathFinderProtocol]
modules: dict[str, ModuleType] modules: dict[str, ModuleType]
if sys.version_info >= (3, 10): if sys.version_info >= (3, 10):
orig_argv: list[str] orig_argv: list[str]
path: list[str] path: list[str]
path_hooks: list[Callable[[str], PathEntryFinder]] path_hooks: list[Callable[[str], PathEntryFinderProtocol]]
path_importer_cache: dict[str, PathEntryFinder | None] path_importer_cache: dict[str, PathEntryFinderProtocol | None]
platform: str platform: str
if sys.version_info >= (3, 9): if sys.version_info >= (3, 9):
platlibdir: str platlibdir: str

View file

@ -374,7 +374,11 @@ class SpooledTemporaryFile(IO[AnyStr], _SpooledTemporaryFileBase):
def readlines(self, hint: int = ..., /) -> list[AnyStr]: ... # type: ignore[override] def readlines(self, hint: int = ..., /) -> list[AnyStr]: ... # type: ignore[override]
def seek(self, offset: int, whence: int = ...) -> int: ... def seek(self, offset: int, whence: int = ...) -> int: ...
def tell(self) -> int: ... def tell(self) -> int: ...
if sys.version_info >= (3, 11):
def truncate(self, size: int | None = None) -> int: ...
else:
def truncate(self, size: int | None = None) -> None: ... # type: ignore[override] def truncate(self, size: int | None = None) -> None: ... # type: ignore[override]
@overload @overload
def write(self: SpooledTemporaryFile[str], s: str) -> int: ... def write(self: SpooledTemporaryFile[str], s: str) -> int: ...
@overload @overload

View file

@ -1,5 +1,6 @@
import sys import sys
from _typeshed import SupportsKeysAndGetItem from _typeshed import SupportsKeysAndGetItem
from _typeshed.importlib import LoaderProtocol
from collections.abc import ( from collections.abc import (
AsyncGenerator, AsyncGenerator,
Awaitable, Awaitable,
@ -16,7 +17,7 @@ from collections.abc import (
from importlib.machinery import ModuleSpec from importlib.machinery import ModuleSpec
# pytype crashes if types.MappingProxyType inherits from collections.abc.Mapping instead of typing.Mapping # pytype crashes if types.MappingProxyType inherits from collections.abc.Mapping instead of typing.Mapping
from typing import Any, ClassVar, Literal, Mapping, Protocol, TypeVar, final, overload # noqa: Y022 from typing import Any, ClassVar, Literal, Mapping, TypeVar, final, overload # noqa: Y022
from typing_extensions import ParamSpec, Self, TypeVarTuple, deprecated from typing_extensions import ParamSpec, Self, TypeVarTuple, deprecated
__all__ = [ __all__ = [
@ -64,18 +65,11 @@ _T2 = TypeVar("_T2")
_KT = TypeVar("_KT") _KT = TypeVar("_KT")
_VT_co = TypeVar("_VT_co", covariant=True) _VT_co = TypeVar("_VT_co", covariant=True)
@final
class _Cell:
def __new__(cls, contents: object = ..., /) -> Self: ...
def __eq__(self, value: object, /) -> bool: ...
__hash__: ClassVar[None] # type: ignore[assignment]
cell_contents: Any
# Make sure this class definition stays roughly in line with `builtins.function` # Make sure this class definition stays roughly in line with `builtins.function`
@final @final
class FunctionType: class FunctionType:
@property @property
def __closure__(self) -> tuple[_Cell, ...] | None: ... def __closure__(self) -> tuple[CellType, ...] | None: ...
__code__: CodeType __code__: CodeType
__defaults__: tuple[Any, ...] | None __defaults__: tuple[Any, ...] | None
__dict__: dict[str, Any] __dict__: dict[str, Any]
@ -98,7 +92,7 @@ class FunctionType:
globals: dict[str, Any], globals: dict[str, Any],
name: str | None = ..., name: str | None = ...,
argdefs: tuple[object, ...] | None = ..., argdefs: tuple[object, ...] | None = ...,
closure: tuple[_Cell, ...] | None = ..., closure: tuple[CellType, ...] | None = ...,
) -> Self: ... ) -> Self: ...
def __call__(self, *args: Any, **kwargs: Any) -> Any: ... def __call__(self, *args: Any, **kwargs: Any) -> Any: ...
@overload @overload
@ -318,15 +312,12 @@ class SimpleNamespace:
def __setattr__(self, name: str, value: Any, /) -> None: ... def __setattr__(self, name: str, value: Any, /) -> None: ...
def __delattr__(self, name: str, /) -> None: ... def __delattr__(self, name: str, /) -> None: ...
class _LoaderProtocol(Protocol):
def load_module(self, fullname: str, /) -> ModuleType: ...
class ModuleType: class ModuleType:
__name__: str __name__: str
__file__: str | None __file__: str | None
@property @property
def __dict__(self) -> dict[str, Any]: ... # type: ignore[override] def __dict__(self) -> dict[str, Any]: ... # type: ignore[override]
__loader__: _LoaderProtocol | None __loader__: LoaderProtocol | None
__package__: str | None __package__: str | None
__path__: MutableSequence[str] __path__: MutableSequence[str]
__spec__: ModuleSpec | None __spec__: ModuleSpec | None
@ -336,6 +327,12 @@ class ModuleType:
# using `builtins.__import__` or `importlib.import_module` less painful # using `builtins.__import__` or `importlib.import_module` less painful
def __getattr__(self, name: str) -> Any: ... def __getattr__(self, name: str) -> Any: ...
@final
class CellType:
def __new__(cls, contents: object = ..., /) -> Self: ...
__hash__: ClassVar[None] # type: ignore[assignment]
cell_contents: Any
_YieldT_co = TypeVar("_YieldT_co", covariant=True) _YieldT_co = TypeVar("_YieldT_co", covariant=True)
_SendT_contra = TypeVar("_SendT_contra", contravariant=True) _SendT_contra = TypeVar("_SendT_contra", contravariant=True)
_ReturnT_co = TypeVar("_ReturnT_co", covariant=True) _ReturnT_co = TypeVar("_ReturnT_co", covariant=True)
@ -405,7 +402,7 @@ class CoroutineType(Coroutine[_YieldT_co, _SendT_contra, _ReturnT_co]):
@final @final
class MethodType: class MethodType:
@property @property
def __closure__(self) -> tuple[_Cell, ...] | None: ... # inherited from the added function def __closure__(self) -> tuple[CellType, ...] | None: ... # inherited from the added function
@property @property
def __defaults__(self) -> tuple[Any, ...] | None: ... # inherited from the added function def __defaults__(self) -> tuple[Any, ...] | None: ... # inherited from the added function
@property @property
@ -570,8 +567,6 @@ def coroutine(func: Callable[_P, Generator[Any, Any, _R]]) -> Callable[_P, Await
@overload @overload
def coroutine(func: _Fn) -> _Fn: ... def coroutine(func: _Fn) -> _Fn: ...
CellType = _Cell
if sys.version_info >= (3, 9): if sys.version_info >= (3, 9):
class GenericAlias: class GenericAlias:
@property @property

View file

@ -8,7 +8,6 @@ import typing_extensions
from _collections_abc import dict_items, dict_keys, dict_values from _collections_abc import dict_items, dict_keys, dict_values
from _typeshed import IdentityFunction, ReadableBuffer, SupportsKeysAndGetItem from _typeshed import IdentityFunction, ReadableBuffer, SupportsKeysAndGetItem
from abc import ABCMeta, abstractmethod from abc import ABCMeta, abstractmethod
from contextlib import AbstractAsyncContextManager, AbstractContextManager
from re import Match as Match, Pattern as Pattern from re import Match as Match, Pattern as Pattern
from types import ( from types import (
BuiltinFunctionType, BuiltinFunctionType,
@ -24,10 +23,10 @@ from types import (
) )
from typing_extensions import Never as _Never, ParamSpec as _ParamSpec from typing_extensions import Never as _Never, ParamSpec as _ParamSpec
if sys.version_info >= (3, 10):
from types import UnionType
if sys.version_info >= (3, 9): if sys.version_info >= (3, 9):
from types import GenericAlias from types import GenericAlias
if sys.version_info >= (3, 10):
from types import UnionType
__all__ = [ __all__ = [
"AbstractSet", "AbstractSet",
@ -402,8 +401,8 @@ class Reversible(Iterable[_T_co], Protocol[_T_co]):
def __reversed__(self) -> Iterator[_T_co]: ... def __reversed__(self) -> Iterator[_T_co]: ...
_YieldT_co = TypeVar("_YieldT_co", covariant=True) _YieldT_co = TypeVar("_YieldT_co", covariant=True)
_SendT_contra = TypeVar("_SendT_contra", contravariant=True) _SendT_contra = TypeVar("_SendT_contra", contravariant=True, default=None)
_ReturnT_co = TypeVar("_ReturnT_co", covariant=True) _ReturnT_co = TypeVar("_ReturnT_co", covariant=True, default=None)
class Generator(Iterator[_YieldT_co], Generic[_YieldT_co, _SendT_contra, _ReturnT_co]): class Generator(Iterator[_YieldT_co], Generic[_YieldT_co, _SendT_contra, _ReturnT_co]):
def __next__(self) -> _YieldT_co: ... def __next__(self) -> _YieldT_co: ...
@ -428,15 +427,15 @@ class Generator(Iterator[_YieldT_co], Generic[_YieldT_co, _SendT_contra, _Return
@property @property
def gi_yieldfrom(self) -> Generator[Any, Any, Any] | None: ... def gi_yieldfrom(self) -> Generator[Any, Any, Any] | None: ...
# NOTE: Technically we would like this to be able to accept a second parameter as well, just # NOTE: Prior to Python 3.13 these aliases are lacking the second _ExitT_co parameter
# like it's counterpart in contextlib, however `typing._SpecialGenericAlias` enforces the if sys.version_info >= (3, 13):
# correct number of arguments at runtime, so we would be hiding runtime errors. from contextlib import AbstractAsyncContextManager as AsyncContextManager, AbstractContextManager as ContextManager
else:
from contextlib import AbstractAsyncContextManager, AbstractContextManager
@runtime_checkable @runtime_checkable
class ContextManager(AbstractContextManager[_T_co, bool | None], Protocol[_T_co]): ... class ContextManager(AbstractContextManager[_T_co, bool | None], Protocol[_T_co]): ...
# NOTE: Technically we would like this to be able to accept a second parameter as well, just
# like it's counterpart in contextlib, however `typing._SpecialGenericAlias` enforces the
# correct number of arguments at runtime, so we would be hiding runtime errors.
@runtime_checkable @runtime_checkable
class AsyncContextManager(AbstractAsyncContextManager[_T_co, bool | None], Protocol[_T_co]): ... class AsyncContextManager(AbstractAsyncContextManager[_T_co, bool | None], Protocol[_T_co]): ...
@ -445,7 +444,11 @@ class Awaitable(Protocol[_T_co]):
@abstractmethod @abstractmethod
def __await__(self) -> Generator[Any, Any, _T_co]: ... def __await__(self) -> Generator[Any, Any, _T_co]: ...
class Coroutine(Awaitable[_ReturnT_co], Generic[_YieldT_co, _SendT_contra, _ReturnT_co]): # Non-default variations to accommodate couroutines, and `AwaitableGenerator` having a 4th type parameter.
_SendT_contra_nd = TypeVar("_SendT_contra_nd", contravariant=True)
_ReturnT_co_nd = TypeVar("_ReturnT_co_nd", covariant=True)
class Coroutine(Awaitable[_ReturnT_co_nd], Generic[_YieldT_co, _SendT_contra_nd, _ReturnT_co_nd]):
__name__: str __name__: str
__qualname__: str __qualname__: str
@property @property
@ -457,7 +460,7 @@ class Coroutine(Awaitable[_ReturnT_co], Generic[_YieldT_co, _SendT_contra, _Retu
@property @property
def cr_running(self) -> bool: ... def cr_running(self) -> bool: ...
@abstractmethod @abstractmethod
def send(self, value: _SendT_contra, /) -> _YieldT_co: ... def send(self, value: _SendT_contra_nd, /) -> _YieldT_co: ...
@overload @overload
@abstractmethod @abstractmethod
def throw( def throw(
@ -473,9 +476,9 @@ class Coroutine(Awaitable[_ReturnT_co], Generic[_YieldT_co, _SendT_contra, _Retu
# The parameters correspond to Generator, but the 4th is the original type. # The parameters correspond to Generator, but the 4th is the original type.
@type_check_only @type_check_only
class AwaitableGenerator( class AwaitableGenerator(
Awaitable[_ReturnT_co], Awaitable[_ReturnT_co_nd],
Generator[_YieldT_co, _SendT_contra, _ReturnT_co], Generator[_YieldT_co, _SendT_contra_nd, _ReturnT_co_nd],
Generic[_YieldT_co, _SendT_contra, _ReturnT_co, _S], Generic[_YieldT_co, _SendT_contra_nd, _ReturnT_co_nd, _S],
metaclass=ABCMeta, metaclass=ABCMeta,
): ... ): ...