Sync vendored typeshed stubs (#16762)

Close and reopen this PR to trigger CI

Co-authored-by: typeshedbot <>
This commit is contained in:
github-actions[bot] 2025-03-15 00:38:58 +00:00 committed by GitHub
parent c755eec91e
commit 1fab292ec1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
28 changed files with 403 additions and 323 deletions

View file

@ -1 +1 @@
0b13c1deb6d0b2cdc78b246da9a0863c87dd8424 cdfb10c340c3df0f8b4112705e6e229b6ae269fd

View file

@ -812,12 +812,12 @@ def getaddrinfo(
type: int = ..., type: int = ...,
proto: int = ..., proto: int = ...,
flags: int = ..., flags: int = ...,
) -> list[tuple[int, int, int, str, tuple[str, int] | tuple[str, int, int, int]]]: ... ) -> list[tuple[int, int, int, str, tuple[str, int] | tuple[str, int, int, int] | tuple[int, bytes]]]: ...
def gethostbyname(hostname: str, /) -> str: ... def gethostbyname(hostname: str, /) -> str: ...
def gethostbyname_ex(hostname: str, /) -> tuple[str, list[str], list[str]]: ... def gethostbyname_ex(hostname: str, /) -> tuple[str, list[str], list[str]]: ...
def gethostname() -> str: ... def gethostname() -> str: ...
def gethostbyaddr(ip_address: str, /) -> tuple[str, list[str], list[str]]: ... def gethostbyaddr(ip_address: str, /) -> tuple[str, list[str], list[str]]: ...
def getnameinfo(sockaddr: tuple[str, int] | tuple[str, int, int, int], flags: int, /) -> tuple[str, str]: ... def getnameinfo(sockaddr: tuple[str, int] | tuple[str, int, int, int] | tuple[int, bytes], flags: int, /) -> tuple[str, str]: ...
def getprotobyname(protocolname: str, /) -> int: ... def getprotobyname(protocolname: str, /) -> int: ...
def getservbyname(servicename: str, protocolname: str = ..., /) -> int: ... def getservbyname(servicename: str, protocolname: str = ..., /) -> int: ...
def getservbyport(port: int, protocolname: str = ..., /) -> str: ... def getservbyport(port: int, protocolname: str = ..., /) -> str: ...

View file

@ -117,6 +117,12 @@ class SupportsSub(Protocol[_T_contra, _T_co]):
class SupportsRSub(Protocol[_T_contra, _T_co]): class SupportsRSub(Protocol[_T_contra, _T_co]):
def __rsub__(self, x: _T_contra, /) -> _T_co: ... def __rsub__(self, x: _T_contra, /) -> _T_co: ...
class SupportsMul(Protocol[_T_contra, _T_co]):
def __mul__(self, x: _T_contra, /) -> _T_co: ...
class SupportsRMul(Protocol[_T_contra, _T_co]):
def __rmul__(self, x: _T_contra, /) -> _T_co: ...
class SupportsDivMod(Protocol[_T_contra, _T_co]): class SupportsDivMod(Protocol[_T_contra, _T_co]):
def __divmod__(self, other: _T_contra, /) -> _T_co: ... def __divmod__(self, other: _T_contra, /) -> _T_co: ...
@ -151,11 +157,8 @@ class SupportsKeysAndGetItem(Protocol[_KT, _VT_co]):
def keys(self) -> Iterable[_KT]: ... def keys(self) -> Iterable[_KT]: ...
def __getitem__(self, key: _KT, /) -> _VT_co: ... def __getitem__(self, key: _KT, /) -> _VT_co: ...
# This protocol is currently under discussion. Use SupportsContainsAndGetItem # stable
# instead, if you require the __contains__ method.
# See https://github.com/python/typeshed/issues/11822.
class SupportsGetItem(Protocol[_KT_contra, _VT_co]): class SupportsGetItem(Protocol[_KT_contra, _VT_co]):
def __contains__(self, x: Any, /) -> bool: ...
def __getitem__(self, key: _KT_contra, /) -> _VT_co: ... def __getitem__(self, key: _KT_contra, /) -> _VT_co: ...
# stable # stable

View file

@ -1,3 +1,5 @@
# ruff: noqa: PLR5501 # This condition is so big, it's clearer to keep to platform condition in two blocks
# Can't NOQA on a specific line: https://github.com/plinss/flake8-noqa/issues/22
import sys import sys
from collections.abc import Awaitable, Coroutine, Generator from collections.abc import Awaitable, Coroutine, Generator
from typing import Any, TypeVar from typing import Any, TypeVar

View file

@ -8,6 +8,7 @@ from asyncio.protocols import BaseProtocol
from asyncio.tasks import Task from asyncio.tasks import Task
from asyncio.transports import BaseTransport, DatagramTransport, ReadTransport, SubprocessTransport, Transport, WriteTransport from asyncio.transports import BaseTransport, DatagramTransport, ReadTransport, SubprocessTransport, Transport, WriteTransport
from collections.abc import Callable, Iterable, Sequence from collections.abc import Callable, Iterable, Sequence
from concurrent.futures import Executor, ThreadPoolExecutor
from contextvars import Context from contextvars import Context
from socket import AddressFamily, SocketKind, _Address, _RetAddress, socket from socket import AddressFamily, SocketKind, _Address, _RetAddress, socket
from typing import IO, Any, Literal, TypeVar, overload from typing import IO, Any, Literal, TypeVar, overload
@ -96,8 +97,8 @@ class BaseEventLoop(AbstractEventLoop):
def call_soon_threadsafe( def call_soon_threadsafe(
self, callback: Callable[[Unpack[_Ts]], object], *args: Unpack[_Ts], context: Context | None = None self, callback: Callable[[Unpack[_Ts]], object], *args: Unpack[_Ts], context: Context | None = None
) -> Handle: ... ) -> Handle: ...
def run_in_executor(self, executor: Any, func: Callable[[Unpack[_Ts]], _T], *args: Unpack[_Ts]) -> Future[_T]: ... def run_in_executor(self, executor: Executor | None, func: Callable[[Unpack[_Ts]], _T], *args: Unpack[_Ts]) -> Future[_T]: ...
def set_default_executor(self, executor: Any) -> None: ... def set_default_executor(self, executor: ThreadPoolExecutor) -> None: ... # type: ignore[override]
# Network I/O methods returning Futures. # Network I/O methods returning Futures.
async def getaddrinfo( async def getaddrinfo(
self, self,

View file

@ -9,6 +9,7 @@ from _asyncio import (
from _typeshed import FileDescriptorLike, ReadableBuffer, StrPath, Unused, WriteableBuffer from _typeshed import FileDescriptorLike, ReadableBuffer, StrPath, Unused, WriteableBuffer
from abc import ABCMeta, abstractmethod from abc import ABCMeta, abstractmethod
from collections.abc import Callable, Sequence from collections.abc import Callable, Sequence
from concurrent.futures import Executor
from contextvars import Context from contextvars import Context
from socket import AddressFamily, SocketKind, _Address, _RetAddress, socket from socket import AddressFamily, SocketKind, _Address, _RetAddress, socket
from typing import IO, Any, Literal, Protocol, TypeVar, overload from typing import IO, Any, Literal, Protocol, TypeVar, overload
@ -188,9 +189,9 @@ class AbstractEventLoop:
def call_soon_threadsafe(self, callback: Callable[[Unpack[_Ts]], object], *args: Unpack[_Ts]) -> Handle: ... def call_soon_threadsafe(self, callback: Callable[[Unpack[_Ts]], object], *args: Unpack[_Ts]) -> Handle: ...
@abstractmethod @abstractmethod
def run_in_executor(self, executor: Any, func: Callable[[Unpack[_Ts]], _T], *args: Unpack[_Ts]) -> Future[_T]: ... def run_in_executor(self, executor: Executor | None, func: Callable[[Unpack[_Ts]], _T], *args: Unpack[_Ts]) -> Future[_T]: ...
@abstractmethod @abstractmethod
def set_default_executor(self, executor: Any) -> None: ... def set_default_executor(self, executor: Executor) -> None: ...
# Network I/O methods returning Futures. # Network I/O methods returning Futures.
@abstractmethod @abstractmethod
async def getaddrinfo( async def getaddrinfo(

View file

@ -1,4 +1,3 @@
# ruff: noqa: PYI036 # This is the module declaring BaseException
import _ast import _ast
import _sitebuiltins import _sitebuiltins
import _typeshed import _typeshed
@ -89,8 +88,8 @@ _T2 = TypeVar("_T2")
_T3 = TypeVar("_T3") _T3 = TypeVar("_T3")
_T4 = TypeVar("_T4") _T4 = TypeVar("_T4")
_T5 = TypeVar("_T5") _T5 = TypeVar("_T5")
_SupportsNextT = TypeVar("_SupportsNextT", bound=SupportsNext[Any], covariant=True) _SupportsNextT_co = TypeVar("_SupportsNextT_co", bound=SupportsNext[Any], covariant=True)
_SupportsAnextT = TypeVar("_SupportsAnextT", bound=SupportsAnext[Any], covariant=True) _SupportsAnextT_co = TypeVar("_SupportsAnextT_co", bound=SupportsAnext[Any], covariant=True)
_AwaitableT = TypeVar("_AwaitableT", bound=Awaitable[Any]) _AwaitableT = TypeVar("_AwaitableT", bound=Awaitable[Any])
_AwaitableT_co = TypeVar("_AwaitableT_co", bound=Awaitable[Any], covariant=True) _AwaitableT_co = TypeVar("_AwaitableT_co", bound=Awaitable[Any], covariant=True)
_P = ParamSpec("_P") _P = ParamSpec("_P")
@ -870,7 +869,11 @@ class memoryview(Sequence[_I]):
def __new__(cls, obj: ReadableBuffer) -> Self: ... def __new__(cls, obj: ReadableBuffer) -> Self: ...
def __enter__(self) -> Self: ... def __enter__(self) -> Self: ...
def __exit__( def __exit__(
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None, / self,
exc_type: type[BaseException] | None, # noqa: PYI036 # This is the module declaring BaseException
exc_val: BaseException | None,
exc_tb: TracebackType | None,
/,
) -> None: ... ) -> None: ...
@overload @overload
def cast(self, format: Literal["c", "@c"], shape: list[int] | tuple[int, ...] = ...) -> memoryview[bytes]: ... def cast(self, format: Literal["c", "@c"], shape: list[int] | tuple[int, ...] = ...) -> memoryview[bytes]: ...
@ -1140,7 +1143,7 @@ class dict(MutableMapping[_KT, _VT]):
def fromkeys(cls, iterable: Iterable[_T], value: _S, /) -> dict[_T, _S]: ... def fromkeys(cls, iterable: Iterable[_T], value: _S, /) -> dict[_T, _S]: ...
# Positional-only in dict, but not in MutableMapping # Positional-only in dict, but not in MutableMapping
@overload # type: ignore[override] @overload # type: ignore[override]
def get(self, key: _KT, /) -> _VT | None: ... def get(self, key: _KT, default: None = None, /) -> _VT | None: ...
@overload @overload
def get(self, key: _KT, default: _VT, /) -> _VT: ... def get(self, key: _KT, default: _VT, /) -> _VT: ...
@overload @overload
@ -1319,7 +1322,7 @@ class _PathLike(Protocol[AnyStr_co]):
def __fspath__(self) -> AnyStr_co: ... def __fspath__(self) -> AnyStr_co: ...
if sys.version_info >= (3, 10): if sys.version_info >= (3, 10):
def aiter(async_iterable: SupportsAiter[_SupportsAnextT], /) -> _SupportsAnextT: ... def aiter(async_iterable: SupportsAiter[_SupportsAnextT_co], /) -> _SupportsAnextT_co: ...
class _SupportsSynchronousAnext(Protocol[_AwaitableT_co]): class _SupportsSynchronousAnext(Protocol[_AwaitableT_co]):
def __anext__(self) -> _AwaitableT_co: ... def __anext__(self) -> _AwaitableT_co: ...
@ -1481,7 +1484,7 @@ class _GetItemIterable(Protocol[_T_co]):
def __getitem__(self, i: int, /) -> _T_co: ... def __getitem__(self, i: int, /) -> _T_co: ...
@overload @overload
def iter(object: SupportsIter[_SupportsNextT], /) -> _SupportsNextT: ... def iter(object: SupportsIter[_SupportsNextT_co], /) -> _SupportsNextT_co: ...
@overload @overload
def iter(object: _GetItemIterable[_T], /) -> Iterator[_T]: ... def iter(object: _GetItemIterable[_T], /) -> Iterator[_T]: ...
@overload @overload
@ -1688,17 +1691,17 @@ def print(
*values: object, sep: str | None = " ", end: str | None = "\n", file: _SupportsWriteAndFlush[str] | None = None, flush: bool *values: object, sep: str | None = " ", end: str | None = "\n", file: _SupportsWriteAndFlush[str] | None = None, flush: bool
) -> None: ... ) -> None: ...
_E = TypeVar("_E", contravariant=True) _E_contra = TypeVar("_E_contra", contravariant=True)
_M = TypeVar("_M", contravariant=True) _M_contra = TypeVar("_M_contra", contravariant=True)
class _SupportsPow2(Protocol[_E, _T_co]): class _SupportsPow2(Protocol[_E_contra, _T_co]):
def __pow__(self, other: _E, /) -> _T_co: ... def __pow__(self, other: _E_contra, /) -> _T_co: ...
class _SupportsPow3NoneOnly(Protocol[_E, _T_co]): class _SupportsPow3NoneOnly(Protocol[_E_contra, _T_co]):
def __pow__(self, other: _E, modulo: None = None, /) -> _T_co: ... def __pow__(self, other: _E_contra, modulo: None = None, /) -> _T_co: ...
class _SupportsPow3(Protocol[_E, _M, _T_co]): class _SupportsPow3(Protocol[_E_contra, _M_contra, _T_co]):
def __pow__(self, other: _E, modulo: _M, /) -> _T_co: ... def __pow__(self, other: _E_contra, modulo: _M_contra, /) -> _T_co: ...
_SupportsSomeKindOfPow = ( # noqa: Y026 # TODO: Use TypeAlias once mypy bugs are fixed _SupportsSomeKindOfPow = ( # noqa: Y026 # TODO: Use TypeAlias once mypy bugs are fixed
_SupportsPow2[Any, Any] | _SupportsPow3NoneOnly[Any, Any] | _SupportsPow3[Any, Any, Any] _SupportsPow2[Any, Any] | _SupportsPow3NoneOnly[Any, Any] | _SupportsPow3[Any, Any, Any]
@ -1734,11 +1737,11 @@ def pow(base: float, exp: complex | _SupportsSomeKindOfPow, mod: None = None) ->
@overload @overload
def pow(base: complex, exp: complex | _SupportsSomeKindOfPow, mod: None = None) -> complex: ... def pow(base: complex, exp: complex | _SupportsSomeKindOfPow, mod: None = None) -> complex: ...
@overload @overload
def pow(base: _SupportsPow2[_E, _T_co], exp: _E, mod: None = None) -> _T_co: ... # type: ignore[overload-overlap] def pow(base: _SupportsPow2[_E_contra, _T_co], exp: _E_contra, mod: None = None) -> _T_co: ... # type: ignore[overload-overlap]
@overload @overload
def pow(base: _SupportsPow3NoneOnly[_E, _T_co], exp: _E, mod: None = None) -> _T_co: ... # type: ignore[overload-overlap] def pow(base: _SupportsPow3NoneOnly[_E_contra, _T_co], exp: _E_contra, mod: None = None) -> _T_co: ... # type: ignore[overload-overlap]
@overload @overload
def pow(base: _SupportsPow3[_E, _M, _T_co], exp: _E, mod: _M) -> _T_co: ... def pow(base: _SupportsPow3[_E_contra, _M_contra, _T_co], exp: _E_contra, mod: _M_contra) -> _T_co: ...
@overload @overload
def pow(base: _SupportsSomeKindOfPow, exp: float, mod: None = None) -> Any: ... def pow(base: _SupportsSomeKindOfPow, exp: float, mod: None = None) -> Any: ...
@overload @overload

View file

@ -33,7 +33,7 @@ _T_co = TypeVar("_T_co", covariant=True)
_T_io = TypeVar("_T_io", bound=IO[str] | None) _T_io = TypeVar("_T_io", bound=IO[str] | None)
_ExitT_co = TypeVar("_ExitT_co", covariant=True, bound=bool | None, default=bool | None) _ExitT_co = TypeVar("_ExitT_co", covariant=True, bound=bool | None, default=bool | None)
_F = TypeVar("_F", bound=Callable[..., Any]) _F = TypeVar("_F", bound=Callable[..., Any])
_G = TypeVar("_G", bound=Generator[Any, Any, Any] | AsyncGenerator[Any, Any], covariant=True) _G_co = TypeVar("_G_co", bound=Generator[Any, Any, Any] | AsyncGenerator[Any, Any], covariant=True)
_P = ParamSpec("_P") _P = ParamSpec("_P")
_SendT_contra = TypeVar("_SendT_contra", contravariant=True, default=None) _SendT_contra = TypeVar("_SendT_contra", contravariant=True, default=None)
@ -68,11 +68,11 @@ class ContextDecorator:
def _recreate_cm(self) -> Self: ... def _recreate_cm(self) -> Self: ...
def __call__(self, func: _F) -> _F: ... def __call__(self, func: _F) -> _F: ...
class _GeneratorContextManagerBase(Generic[_G]): class _GeneratorContextManagerBase(Generic[_G_co]):
# Ideally this would use ParamSpec, but that requires (*args, **kwargs), which this isn't. see #6676 # Ideally this would use ParamSpec, but that requires (*args, **kwargs), which this isn't. see #6676
def __init__(self, func: Callable[..., _G], args: tuple[Any, ...], kwds: dict[str, Any]) -> None: ... def __init__(self, func: Callable[..., _G_co], args: tuple[Any, ...], kwds: dict[str, Any]) -> None: ...
gen: _G gen: _G_co
func: Callable[..., _G] func: Callable[..., _G_co]
args: tuple[Any, ...] args: tuple[Any, ...]
kwds: dict[str, Any] kwds: dict[str, Any]

View file

@ -30,7 +30,7 @@ _CommandT = TypeVar("_CommandT", bound=Command)
_Ts = TypeVarTuple("_Ts") _Ts = TypeVarTuple("_Ts")
class Command: class Command:
dry_run: Literal[0, 1] # Exposed from __getattr_. Same as Distribution.dry_run dry_run: bool | Literal[0, 1] # Exposed from __getattr_. Same as Distribution.dry_run
distribution: Distribution distribution: Distribution
# Any to work around variance issues # Any to work around variance issues
sub_commands: ClassVar[list[tuple[str, Callable[[Any], bool] | None]]] sub_commands: ClassVar[list[tuple[str, Callable[[Any], bool] | None]]]

View file

@ -88,9 +88,9 @@ class Distribution:
display_options: ClassVar[_OptionsList] display_options: ClassVar[_OptionsList]
display_option_names: ClassVar[list[str]] display_option_names: ClassVar[list[str]]
negative_opt: ClassVar[dict[str, str]] negative_opt: ClassVar[dict[str, str]]
verbose: Literal[0, 1] verbose: bool | Literal[0, 1]
dry_run: Literal[0, 1] dry_run: bool | Literal[0, 1]
help: Literal[0, 1] help: bool | Literal[0, 1]
command_packages: list[str] | None command_packages: list[str] | None
script_name: str | None script_name: str | None
script_args: list[str] | None script_args: list[str] | None

View file

@ -1,10 +1,10 @@
from collections.abc import Iterable, Mapping from collections.abc import Iterable, Mapping
from getopt import _SliceableT, _StrSequenceT_co
from re import Pattern from re import Pattern
from typing import Any, Final, overload from typing import Any, Final, overload
from typing_extensions import TypeAlias from typing_extensions import TypeAlias
_Option: TypeAlias = tuple[str, str | None, str] _Option: TypeAlias = tuple[str, str | None, str]
_GR: TypeAlias = tuple[list[str], OptionDummy]
longopt_pat: Final = r"[a-zA-Z](?:[a-zA-Z0-9-]*)" longopt_pat: Final = r"[a-zA-Z](?:[a-zA-Z0-9-]*)"
longopt_re: Final[Pattern[str]] longopt_re: Final[Pattern[str]]
@ -15,15 +15,25 @@ class FancyGetopt:
def __init__(self, option_table: list[_Option] | None = None) -> None: ... def __init__(self, option_table: list[_Option] | None = None) -> None: ...
# TODO kinda wrong, `getopt(object=object())` is invalid # TODO kinda wrong, `getopt(object=object())` is invalid
@overload @overload
def getopt(self, args: list[str] | None = None) -> _GR: ... def getopt(
self, args: _SliceableT[_StrSequenceT_co] | None = None, object: None = None
) -> tuple[_StrSequenceT_co, OptionDummy]: ...
@overload @overload
def getopt(self, args: list[str] | None, object: Any) -> list[str]: ... def getopt(
self, args: _SliceableT[_StrSequenceT_co] | None, object: Any
) -> _StrSequenceT_co: ... # object is an arbitrary non-slotted object
def get_option_order(self) -> list[tuple[str, str]]: ... def get_option_order(self) -> list[tuple[str, str]]: ...
def generate_help(self, header: str | None = None) -> list[str]: ... def generate_help(self, header: str | None = None) -> list[str]: ...
# Same note as FancyGetopt.getopt
@overload
def fancy_getopt( def fancy_getopt(
options: list[_Option], negative_opt: Mapping[_Option, _Option], object: Any, args: list[str] | None options: list[_Option], negative_opt: Mapping[_Option, _Option], object: None, args: _SliceableT[_StrSequenceT_co] | None
) -> list[str] | _GR: ... ) -> tuple[_StrSequenceT_co, OptionDummy]: ...
@overload
def fancy_getopt(
options: list[_Option], negative_opt: Mapping[_Option, _Option], object: Any, args: _SliceableT[_StrSequenceT_co] | None
) -> _StrSequenceT_co: ...
WS_TRANS: Final[dict[int, str]] WS_TRANS: Final[dict[int, str]]

View file

@ -151,20 +151,25 @@ class partialmethod(Generic[_T]):
if sys.version_info >= (3, 9): if sys.version_info >= (3, 9):
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ... def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
if sys.version_info >= (3, 11):
_RegType: TypeAlias = type[Any] | types.UnionType
else:
_RegType: TypeAlias = type[Any]
class _SingleDispatchCallable(Generic[_T]): class _SingleDispatchCallable(Generic[_T]):
registry: types.MappingProxyType[Any, Callable[..., _T]] registry: types.MappingProxyType[Any, Callable[..., _T]]
def dispatch(self, cls: Any) -> Callable[..., _T]: ... def dispatch(self, cls: Any) -> Callable[..., _T]: ...
# @fun.register(complex) # @fun.register(complex)
# def _(arg, verbose=False): ... # def _(arg, verbose=False): ...
@overload @overload
def register(self, cls: type[Any], func: None = None) -> Callable[[Callable[..., _T]], Callable[..., _T]]: ... def register(self, cls: _RegType, func: None = None) -> Callable[[Callable[..., _T]], Callable[..., _T]]: ...
# @fun.register # @fun.register
# def _(arg: int, verbose=False): # def _(arg: int, verbose=False):
@overload @overload
def register(self, cls: Callable[..., _T], func: None = None) -> Callable[..., _T]: ... def register(self, cls: Callable[..., _T], func: None = None) -> Callable[..., _T]: ...
# fun.register(int, lambda x: x) # fun.register(int, lambda x: x)
@overload @overload
def register(self, cls: type[Any], func: Callable[..., _T]) -> Callable[..., _T]: ... def register(self, cls: _RegType, func: Callable[..., _T]) -> Callable[..., _T]: ...
def _clear_cache(self) -> None: ... def _clear_cache(self) -> None: ...
def __call__(self, /, *args: Any, **kwargs: Any) -> _T: ... def __call__(self, /, *args: Any, **kwargs: Any) -> _T: ...
@ -177,11 +182,11 @@ class singledispatchmethod(Generic[_T]):
@property @property
def __isabstractmethod__(self) -> bool: ... def __isabstractmethod__(self) -> bool: ...
@overload @overload
def register(self, cls: type[Any], method: None = None) -> Callable[[Callable[..., _T]], Callable[..., _T]]: ... def register(self, cls: _RegType, method: None = None) -> Callable[[Callable[..., _T]], Callable[..., _T]]: ...
@overload @overload
def register(self, cls: Callable[..., _T], method: None = None) -> Callable[..., _T]: ... def register(self, cls: Callable[..., _T], method: None = None) -> Callable[..., _T]: ...
@overload @overload
def register(self, cls: type[Any], method: Callable[..., _T]) -> Callable[..., _T]: ... def register(self, cls: _RegType, method: Callable[..., _T]) -> Callable[..., _T]: ...
def __get__(self, obj: _S, cls: type[_S] | None = None) -> Callable[..., _T]: ... def __get__(self, obj: _S, cls: type[_S] | None = None) -> Callable[..., _T]: ...
class cached_property(Generic[_T_co]): class cached_property(Generic[_T_co]):

View file

@ -1,10 +1,22 @@
from collections.abc import Iterable from collections.abc import Iterable, Sequence
from typing import Protocol, TypeVar, overload, type_check_only
_StrSequenceT_co = TypeVar("_StrSequenceT_co", covariant=True, bound=Sequence[str])
@type_check_only
class _SliceableT(Protocol[_StrSequenceT_co]):
@overload
def __getitem__(self, key: int, /) -> str: ...
@overload
def __getitem__(self, key: slice, /) -> _StrSequenceT_co: ...
__all__ = ["GetoptError", "error", "getopt", "gnu_getopt"] __all__ = ["GetoptError", "error", "getopt", "gnu_getopt"]
def getopt(args: list[str], shortopts: str, longopts: Iterable[str] | str = []) -> tuple[list[tuple[str, str]], list[str]]: ... def getopt(
args: _SliceableT[_StrSequenceT_co], shortopts: str, longopts: Iterable[str] | str = []
) -> tuple[list[tuple[str, str]], _StrSequenceT_co]: ...
def gnu_getopt( def gnu_getopt(
args: list[str], shortopts: str, longopts: Iterable[str] | str = [] args: Sequence[str], shortopts: str, longopts: Iterable[str] | str = []
) -> tuple[list[tuple[str, str]], list[str]]: ... ) -> tuple[list[tuple[str, str]], list[str]]: ...
class GetoptError(Exception): class GetoptError(Exception):

View file

@ -139,7 +139,7 @@ if sys.version_info >= (3, 10) and sys.version_info < (3, 12):
class Deprecated(Generic[_KT, _VT]): class Deprecated(Generic[_KT, _VT]):
def __getitem__(self, name: _KT) -> _VT: ... def __getitem__(self, name: _KT) -> _VT: ...
@overload @overload
def get(self, name: _KT) -> _VT | None: ... def get(self, name: _KT, default: None = None) -> _VT | None: ...
@overload @overload
def get(self, name: _KT, default: _T) -> _VT | _T: ... def get(self, name: _KT, default: _T) -> _VT | _T: ...
def __iter__(self) -> Iterator[_KT]: ... def __iter__(self) -> Iterator[_KT]: ...

View file

@ -16,9 +16,9 @@ if sys.version_info >= (3, 10):
from zipimport import zipimporter from zipimport import zipimporter
if sys.version_info >= (3, 11): if sys.version_info >= (3, 11):
import importlib.resources.abc as abc from importlib.resources import abc
else: else:
import importlib.abc as abc from importlib import abc
if sys.version_info >= (3, 10): if sys.version_info >= (3, 10):
if sys.version_info >= (3, 11): if sys.version_info >= (3, 11):

View file

@ -143,8 +143,8 @@ if sys.version_info >= (3, 11):
_P = ParamSpec("_P") _P = ParamSpec("_P")
_T = TypeVar("_T") _T = TypeVar("_T")
_F = TypeVar("_F", bound=Callable[..., Any]) _F = TypeVar("_F", bound=Callable[..., Any])
_T_cont = TypeVar("_T_cont", contravariant=True) _T_contra = TypeVar("_T_contra", contravariant=True)
_V_cont = TypeVar("_V_cont", contravariant=True) _V_contra = TypeVar("_V_contra", contravariant=True)
# #
# Types and members # Types and members
@ -228,11 +228,11 @@ def isasyncgenfunction(obj: Callable[_P, Any]) -> TypeGuard[Callable[_P, AsyncGe
@overload @overload
def isasyncgenfunction(obj: object) -> TypeGuard[Callable[..., AsyncGeneratorType[Any, Any]]]: ... def isasyncgenfunction(obj: object) -> TypeGuard[Callable[..., AsyncGeneratorType[Any, Any]]]: ...
class _SupportsSet(Protocol[_T_cont, _V_cont]): class _SupportsSet(Protocol[_T_contra, _V_contra]):
def __set__(self, instance: _T_cont, value: _V_cont, /) -> None: ... def __set__(self, instance: _T_contra, value: _V_contra, /) -> None: ...
class _SupportsDelete(Protocol[_T_cont]): class _SupportsDelete(Protocol[_T_contra]):
def __delete__(self, instance: _T_cont, /) -> None: ... def __delete__(self, instance: _T_contra, /) -> None: ...
def isasyncgen(object: object) -> TypeIs[AsyncGeneratorType[Any, Any]]: ... def isasyncgen(object: object) -> TypeIs[AsyncGeneratorType[Any, Any]]: ...
def istraceback(object: object) -> TypeIs[TracebackType]: ... def istraceback(object: object) -> TypeIs[TracebackType]: ...

View file

@ -1,6 +1,7 @@
import sys import sys
from _typeshed import SupportsMul, SupportsRMul
from collections.abc import Iterable from collections.abc import Iterable
from typing import Final, Protocol, SupportsFloat, SupportsIndex, TypeVar, overload from typing import Any, Final, Literal, Protocol, SupportsFloat, SupportsIndex, TypeVar, overload
from typing_extensions import TypeAlias from typing_extensions import TypeAlias
_T = TypeVar("_T") _T = TypeVar("_T")
@ -99,10 +100,29 @@ elif sys.version_info >= (3, 9):
def perm(n: SupportsIndex, k: SupportsIndex | None = None, /) -> int: ... def perm(n: SupportsIndex, k: SupportsIndex | None = None, /) -> int: ...
def pow(x: _SupportsFloatOrIndex, y: _SupportsFloatOrIndex, /) -> float: ... def pow(x: _SupportsFloatOrIndex, y: _SupportsFloatOrIndex, /) -> float: ...
_PositiveInteger: TypeAlias = Literal[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]
_NegativeInteger: TypeAlias = Literal[-1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15, -16, -17, -18, -19, -20]
_LiteralInteger = _PositiveInteger | _NegativeInteger | Literal[0] # noqa: Y026 # TODO: Use TypeAlias once mypy bugs are fixed
_MultiplicableT1 = TypeVar("_MultiplicableT1", bound=SupportsMul[Any, Any])
_MultiplicableT2 = TypeVar("_MultiplicableT2", bound=SupportsMul[Any, Any])
class _SupportsProdWithNoDefaultGiven(SupportsMul[Any, Any], SupportsRMul[int, Any], Protocol): ...
_SupportsProdNoDefaultT = TypeVar("_SupportsProdNoDefaultT", bound=_SupportsProdWithNoDefaultGiven)
# This stub is based on the type stub for `builtins.sum`.
# Like `builtins.sum`, it cannot be precisely represented in a type stub
# without introducing many false positives.
# For more details on its limitations and false positives, see #13572.
# Instead, just like `builtins.sum`, we explicitly handle several useful cases.
@overload @overload
def prod(iterable: Iterable[SupportsIndex], /, *, start: SupportsIndex = 1) -> int: ... # type: ignore[overload-overlap] def prod(iterable: Iterable[bool | _LiteralInteger], /, *, start: int = 1) -> int: ... # type: ignore[overload-overlap]
@overload @overload
def prod(iterable: Iterable[_SupportsFloatOrIndex], /, *, start: _SupportsFloatOrIndex = 1) -> float: ... def prod(iterable: Iterable[_SupportsProdNoDefaultT], /) -> _SupportsProdNoDefaultT | Literal[1]: ...
@overload
def prod(iterable: Iterable[_MultiplicableT1], /, *, start: _MultiplicableT2) -> _MultiplicableT1 | _MultiplicableT2: ...
def radians(x: _SupportsFloatOrIndex, /) -> float: ... def radians(x: _SupportsFloatOrIndex, /) -> float: ...
def remainder(x: _SupportsFloatOrIndex, y: _SupportsFloatOrIndex, /) -> float: ... def remainder(x: _SupportsFloatOrIndex, y: _SupportsFloatOrIndex, /) -> float: ...
def sin(x: _SupportsFloatOrIndex, /) -> float: ... def sin(x: _SupportsFloatOrIndex, /) -> float: ...

View file

@ -12,10 +12,10 @@ __all__ = ["Client", "Listener", "Pipe", "wait"]
_Address: TypeAlias = str | tuple[str, int] _Address: TypeAlias = str | tuple[str, int]
# Defaulting to Any to avoid forcing generics on a lot of pre-existing code # Defaulting to Any to avoid forcing generics on a lot of pre-existing code
_SendT = TypeVar("_SendT", contravariant=True, default=Any) _SendT_contra = TypeVar("_SendT_contra", contravariant=True, default=Any)
_RecvT = TypeVar("_RecvT", covariant=True, default=Any) _RecvT_co = TypeVar("_RecvT_co", covariant=True, default=Any)
class _ConnectionBase(Generic[_SendT, _RecvT]): class _ConnectionBase(Generic[_SendT_contra, _RecvT_co]):
def __init__(self, handle: SupportsIndex, readable: bool = True, writable: bool = True) -> None: ... def __init__(self, handle: SupportsIndex, readable: bool = True, writable: bool = True) -> None: ...
@property @property
def closed(self) -> bool: ... # undocumented def closed(self) -> bool: ... # undocumented
@ -26,10 +26,10 @@ class _ConnectionBase(Generic[_SendT, _RecvT]):
def fileno(self) -> int: ... def fileno(self) -> int: ...
def close(self) -> None: ... def close(self) -> None: ...
def send_bytes(self, buf: ReadableBuffer, offset: int = 0, size: int | None = None) -> None: ... def send_bytes(self, buf: ReadableBuffer, offset: int = 0, size: int | None = None) -> None: ...
def send(self, obj: _SendT) -> None: ... def send(self, obj: _SendT_contra) -> None: ...
def recv_bytes(self, maxlength: int | None = None) -> bytes: ... def recv_bytes(self, maxlength: int | None = None) -> bytes: ...
def recv_bytes_into(self, buf: Any, offset: int = 0) -> int: ... def recv_bytes_into(self, buf: Any, offset: int = 0) -> int: ...
def recv(self) -> _RecvT: ... def recv(self) -> _RecvT_co: ...
def poll(self, timeout: float | None = 0.0) -> bool: ... def poll(self, timeout: float | None = 0.0) -> bool: ...
def __enter__(self) -> Self: ... def __enter__(self) -> Self: ...
def __exit__( def __exit__(
@ -37,10 +37,10 @@ class _ConnectionBase(Generic[_SendT, _RecvT]):
) -> None: ... ) -> None: ...
def __del__(self) -> None: ... def __del__(self) -> None: ...
class Connection(_ConnectionBase[_SendT, _RecvT]): ... class Connection(_ConnectionBase[_SendT_contra, _RecvT_co]): ...
if sys.platform == "win32": if sys.platform == "win32":
class PipeConnection(_ConnectionBase[_SendT, _RecvT]): ... class PipeConnection(_ConnectionBase[_SendT_contra, _RecvT_co]): ...
class Listener: class Listener:
def __init__( def __init__(
@ -66,8 +66,8 @@ else:
def answer_challenge(connection: Connection[Any, Any], authkey: bytes) -> None: ... def answer_challenge(connection: Connection[Any, Any], authkey: bytes) -> None: ...
def wait( def wait(
object_list: Iterable[Connection[_SendT, _RecvT] | socket.socket | int], timeout: float | None = None object_list: Iterable[Connection[_SendT_contra, _RecvT_co] | socket.socket | int], timeout: float | None = None
) -> list[Connection[_SendT, _RecvT] | socket.socket | int]: ... ) -> list[Connection[_SendT_contra, _RecvT_co] | socket.socket | int]: ...
def Client(address: _Address, family: str | None = None, authkey: bytes | None = None) -> Connection[Any, Any]: ... def Client(address: _Address, family: str | None = None, authkey: bytes | None = None) -> Connection[Any, Any]: ...
# N.B. Keep this in sync with multiprocessing.context.BaseContext.Pipe. # N.B. Keep this in sync with multiprocessing.context.BaseContext.Pipe.

View file

@ -16,7 +16,7 @@ from io import BufferedRandom, BufferedReader, BufferedWriter, FileIO, TextIOWra
from os import PathLike, stat_result from os import PathLike, stat_result
from types import TracebackType from types import TracebackType
from typing import IO, Any, BinaryIO, ClassVar, Literal, overload from typing import IO, Any, BinaryIO, ClassVar, Literal, overload
from typing_extensions import Self, deprecated from typing_extensions import Never, Self, deprecated
if sys.version_info >= (3, 9): if sys.version_info >= (3, 9):
from types import GenericAlias from types import GenericAlias
@ -226,9 +226,13 @@ class Path(PurePath):
def open( def open(
self, mode: str, buffering: int = -1, encoding: str | None = None, errors: str | None = None, newline: str | None = None self, mode: str, buffering: int = -1, encoding: str | None = None, errors: str | None = None, newline: str | None = None
) -> IO[Any]: ... ) -> IO[Any]: ...
if sys.platform != "win32":
# These methods do "exist" on Windows, but they always raise NotImplementedError, # These methods do "exist" on Windows on <3.13, but they always raise NotImplementedError.
# so it's safer to pretend they don't exist if sys.platform == "win32":
if sys.version_info < (3, 13):
def owner(self: Never) -> str: ... # type: ignore[misc]
def group(self: Never) -> str: ... # type: ignore[misc]
else:
if sys.version_info >= (3, 13): if sys.version_info >= (3, 13):
def owner(self, *, follow_symlinks: bool = True) -> str: ... def owner(self, *, follow_symlinks: bool = True) -> str: ...
def group(self, *, follow_symlinks: bool = True) -> str: ... def group(self, *, follow_symlinks: bool = True) -> str: ...
@ -238,7 +242,9 @@ class Path(PurePath):
# This method does "exist" on Windows on <3.12, but always raises NotImplementedError # This method does "exist" on Windows on <3.12, but always raises NotImplementedError
# On py312+, it works properly on Windows, as with all other platforms # On py312+, it works properly on Windows, as with all other platforms
if sys.platform != "win32" or sys.version_info >= (3, 12): if sys.platform == "win32" and sys.version_info < (3, 12):
def is_mount(self: Never) -> bool: ... # type: ignore[misc]
else:
def is_mount(self) -> bool: ... def is_mount(self) -> bool: ...
if sys.version_info >= (3, 9): if sys.version_info >= (3, 9):

View file

@ -3,7 +3,7 @@ import sys
from _typeshed import BytesPath, ExcInfo, FileDescriptorOrPath, StrOrBytesPath, StrPath, SupportsRead, SupportsWrite from _typeshed import BytesPath, ExcInfo, FileDescriptorOrPath, StrOrBytesPath, StrPath, SupportsRead, SupportsWrite
from collections.abc import Callable, Iterable, Sequence from collections.abc import Callable, Iterable, Sequence
from tarfile import _TarfileFilter from tarfile import _TarfileFilter
from typing import Any, AnyStr, NamedTuple, Protocol, TypeVar, overload from typing import Any, AnyStr, NamedTuple, NoReturn, Protocol, TypeVar, overload
from typing_extensions import TypeAlias, deprecated from typing_extensions import TypeAlias, deprecated
__all__ = [ __all__ = [
@ -36,7 +36,6 @@ __all__ = [
] ]
_StrOrBytesPathT = TypeVar("_StrOrBytesPathT", bound=StrOrBytesPath) _StrOrBytesPathT = TypeVar("_StrOrBytesPathT", bound=StrOrBytesPath)
_StrPathT = TypeVar("_StrPathT", bound=StrPath)
# Return value of some functions that may either return a path-like object that was passed in or # Return value of some functions that may either return a path-like object that was passed in or
# a string # a string
_PathReturn: TypeAlias = Any _PathReturn: TypeAlias = Any
@ -185,8 +184,13 @@ else:
@overload @overload
def chown(path: FileDescriptorOrPath, user: str | int, group: str | int) -> None: ... def chown(path: FileDescriptorOrPath, user: str | int, group: str | int) -> None: ...
if sys.platform == "win32" and sys.version_info < (3, 12):
@overload
@deprecated("On Windows before Python 3.12, using a PathLike as `cmd` would always fail or return `None`.")
def which(cmd: os.PathLike[str], mode: int = 1, path: StrPath | None = None) -> NoReturn: ...
@overload @overload
def which(cmd: _StrPathT, mode: int = 1, path: StrPath | None = None) -> str | _StrPathT | None: ... def which(cmd: StrPath, mode: int = 1, path: StrPath | None = None) -> str | None: ...
@overload @overload
def which(cmd: bytes, mode: int = 1, path: StrPath | None = None) -> bytes | None: ... def which(cmd: bytes, mode: int = 1, path: StrPath | None = None) -> bytes | None: ...
def make_archive( def make_archive(

View file

@ -38,29 +38,22 @@ _AfInetAddress: TypeAlias = tuple[str | bytes | bytearray, int] # address accep
# This can possibly be generic at some point: # This can possibly be generic at some point:
class BaseServer: class BaseServer:
address_family: int
server_address: _Address server_address: _Address
socket: _socket
allow_reuse_address: bool
request_queue_size: int
socket_type: int
timeout: float | None timeout: float | None
RequestHandlerClass: Callable[[Any, _RetAddress, Self], BaseRequestHandler] RequestHandlerClass: Callable[[Any, _RetAddress, Self], BaseRequestHandler]
def __init__( def __init__(
self, server_address: _Address, RequestHandlerClass: Callable[[Any, _RetAddress, Self], BaseRequestHandler] self, server_address: _Address, RequestHandlerClass: Callable[[Any, _RetAddress, Self], BaseRequestHandler]
) -> None: ... ) -> None: ...
def fileno(self) -> int: ...
def handle_request(self) -> None: ... def handle_request(self) -> None: ...
def serve_forever(self, poll_interval: float = 0.5) -> None: ... def serve_forever(self, poll_interval: float = 0.5) -> None: ...
def shutdown(self) -> None: ... def shutdown(self) -> None: ...
def server_close(self) -> None: ... def server_close(self) -> None: ...
def finish_request(self, request: _RequestType, client_address: _RetAddress) -> None: ... def finish_request(self, request: _RequestType, client_address: _RetAddress) -> None: ...
def get_request(self) -> tuple[Any, Any]: ... def get_request(self) -> tuple[Any, Any]: ... # Not implemented here, but expected to exist on subclasses
def handle_error(self, request: _RequestType, client_address: _RetAddress) -> None: ... def handle_error(self, request: _RequestType, client_address: _RetAddress) -> None: ...
def handle_timeout(self) -> None: ... def handle_timeout(self) -> None: ...
def process_request(self, request: _RequestType, client_address: _RetAddress) -> None: ... def process_request(self, request: _RequestType, client_address: _RetAddress) -> None: ...
def server_activate(self) -> None: ... def server_activate(self) -> None: ...
def server_bind(self) -> None: ...
def verify_request(self, request: _RequestType, client_address: _RetAddress) -> bool: ... def verify_request(self, request: _RequestType, client_address: _RetAddress) -> bool: ...
def __enter__(self) -> Self: ... def __enter__(self) -> Self: ...
def __exit__( def __exit__(
@ -71,6 +64,11 @@ class BaseServer:
def close_request(self, request: _RequestType) -> None: ... # undocumented def close_request(self, request: _RequestType) -> None: ... # undocumented
class TCPServer(BaseServer): class TCPServer(BaseServer):
address_family: int
socket: _socket
allow_reuse_address: bool
request_queue_size: int
socket_type: int
if sys.version_info >= (3, 11): if sys.version_info >= (3, 11):
allow_reuse_port: bool allow_reuse_port: bool
server_address: _AfInetAddress server_address: _AfInetAddress
@ -80,7 +78,9 @@ class TCPServer(BaseServer):
RequestHandlerClass: Callable[[Any, _RetAddress, Self], BaseRequestHandler], RequestHandlerClass: Callable[[Any, _RetAddress, Self], BaseRequestHandler],
bind_and_activate: bool = True, bind_and_activate: bool = True,
) -> None: ... ) -> None: ...
def fileno(self) -> int: ...
def get_request(self) -> tuple[_socket, _RetAddress]: ... def get_request(self) -> tuple[_socket, _RetAddress]: ...
def server_bind(self) -> None: ...
class UDPServer(TCPServer): class UDPServer(TCPServer):
max_packet_size: ClassVar[int] max_packet_size: ClassVar[int]

View file

@ -103,166 +103,6 @@ PAX_NAME_FIELDS: set[str]
ENCODING: str ENCODING: str
@overload
def open(
name: StrOrBytesPath | None = None,
mode: Literal["r", "r:*", "r:", "r:gz", "r:bz2", "r:xz"] = "r",
fileobj: IO[bytes] | None = None,
bufsize: int = 10240,
*,
format: int | None = ...,
tarinfo: type[TarInfo] | None = ...,
dereference: bool | None = ...,
ignore_zeros: bool | None = ...,
encoding: str | None = ...,
errors: str = ...,
pax_headers: Mapping[str, str] | None = ...,
debug: int | None = ...,
errorlevel: int | None = ...,
) -> TarFile: ...
@overload
def open(
name: StrOrBytesPath | None,
mode: Literal["x", "x:", "a", "a:", "w", "w:", "w:tar"],
fileobj: _Fileobj | None = None,
bufsize: int = 10240,
*,
format: int | None = ...,
tarinfo: type[TarInfo] | None = ...,
dereference: bool | None = ...,
ignore_zeros: bool | None = ...,
encoding: str | None = ...,
errors: str = ...,
pax_headers: Mapping[str, str] | None = ...,
debug: int | None = ...,
errorlevel: int | None = ...,
) -> TarFile: ...
@overload
def open(
name: StrOrBytesPath | None = None,
*,
mode: Literal["x", "x:", "a", "a:", "w", "w:", "w:tar"],
fileobj: _Fileobj | None = None,
bufsize: int = 10240,
format: int | None = ...,
tarinfo: type[TarInfo] | None = ...,
dereference: bool | None = ...,
ignore_zeros: bool | None = ...,
encoding: str | None = ...,
errors: str = ...,
pax_headers: Mapping[str, str] | None = ...,
debug: int | None = ...,
errorlevel: int | None = ...,
) -> TarFile: ...
@overload
def open(
name: StrOrBytesPath | None,
mode: Literal["x:gz", "x:bz2", "w:gz", "w:bz2"],
fileobj: _Fileobj | None = None,
bufsize: int = 10240,
*,
format: int | None = ...,
tarinfo: type[TarInfo] | None = ...,
dereference: bool | None = ...,
ignore_zeros: bool | None = ...,
encoding: str | None = ...,
errors: str = ...,
pax_headers: Mapping[str, str] | None = ...,
debug: int | None = ...,
errorlevel: int | None = ...,
compresslevel: int = 9,
) -> TarFile: ...
@overload
def open(
name: StrOrBytesPath | None = None,
*,
mode: Literal["x:gz", "x:bz2", "w:gz", "w:bz2"],
fileobj: _Fileobj | None = None,
bufsize: int = 10240,
format: int | None = ...,
tarinfo: type[TarInfo] | None = ...,
dereference: bool | None = ...,
ignore_zeros: bool | None = ...,
encoding: str | None = ...,
errors: str = ...,
pax_headers: Mapping[str, str] | None = ...,
debug: int | None = ...,
errorlevel: int | None = ...,
compresslevel: int = 9,
) -> TarFile: ...
@overload
def open(
name: StrOrBytesPath | None,
mode: Literal["x:xz", "w:xz"],
fileobj: _Fileobj | None = None,
bufsize: int = 10240,
*,
format: int | None = ...,
tarinfo: type[TarInfo] | None = ...,
dereference: bool | None = ...,
ignore_zeros: bool | None = ...,
encoding: str | None = ...,
errors: str = ...,
pax_headers: Mapping[str, str] | None = ...,
debug: int | None = ...,
errorlevel: int | None = ...,
preset: Literal[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] | None = ...,
) -> TarFile: ...
@overload
def open(
name: StrOrBytesPath | None = None,
*,
mode: Literal["x:xz", "w:xz"],
fileobj: _Fileobj | None = None,
bufsize: int = 10240,
format: int | None = ...,
tarinfo: type[TarInfo] | None = ...,
dereference: bool | None = ...,
ignore_zeros: bool | None = ...,
encoding: str | None = ...,
errors: str = ...,
pax_headers: Mapping[str, str] | None = ...,
debug: int | None = ...,
errorlevel: int | None = ...,
preset: Literal[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] | None = ...,
) -> TarFile: ...
@overload
def open(
name: StrOrBytesPath | ReadableBuffer | None = None,
*,
mode: Literal["r|*", "r|", "r|gz", "r|bz2", "r|xz"],
fileobj: IO[bytes] | None = None,
bufsize: int = 10240,
format: int | None = ...,
tarinfo: type[TarInfo] | None = ...,
dereference: bool | None = ...,
ignore_zeros: bool | None = ...,
encoding: str | None = ...,
errors: str = ...,
pax_headers: Mapping[str, str] | None = ...,
debug: int | None = ...,
errorlevel: int | None = ...,
preset: int | None = ...,
) -> TarFile: ...
@overload
def open(
name: StrOrBytesPath | WriteableBuffer | None = None,
*,
mode: Literal["w|", "w|gz", "w|bz2", "w|xz"],
fileobj: IO[bytes] | None = None,
bufsize: int = 10240,
format: int | None = ...,
tarinfo: type[TarInfo] | None = ...,
dereference: bool | None = ...,
ignore_zeros: bool | None = ...,
encoding: str | None = ...,
errors: str = ...,
pax_headers: Mapping[str, str] | None = ...,
debug: int | None = ...,
errorlevel: int | None = ...,
preset: int | None = ...,
) -> TarFile: ...
class ExFileObject(io.BufferedReader): class ExFileObject(io.BufferedReader):
def __init__(self, tarfile: TarFile, tarinfo: TarInfo) -> None: ... def __init__(self, tarfile: TarFile, tarinfo: TarInfo) -> None: ...
@ -325,12 +165,13 @@ class TarFile:
self, type: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None self, type: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None
) -> None: ... ) -> None: ...
def __iter__(self) -> Iterator[TarInfo]: ... def __iter__(self) -> Iterator[TarInfo]: ...
@overload
@classmethod @classmethod
def open( def open(
cls, cls,
name: StrOrBytesPath | None = None, name: StrOrBytesPath | None = None,
mode: str = "r", mode: Literal["r", "r:*", "r:", "r:gz", "r:bz2", "r:xz"] = "r",
fileobj: IO[bytes] | None = None, # depends on mode fileobj: _Fileobj | None = None,
bufsize: int = 10240, bufsize: int = 10240,
*, *,
format: int | None = ..., format: int | None = ...,
@ -343,6 +184,182 @@ class TarFile:
debug: int | None = ..., debug: int | None = ...,
errorlevel: int | None = ..., errorlevel: int | None = ...,
) -> Self: ... ) -> Self: ...
@overload
@classmethod
def open(
cls,
name: StrOrBytesPath | None,
mode: Literal["x", "x:", "a", "a:", "w", "w:", "w:tar"],
fileobj: _Fileobj | None = None,
bufsize: int = 10240,
*,
format: int | None = ...,
tarinfo: type[TarInfo] | None = ...,
dereference: bool | None = ...,
ignore_zeros: bool | None = ...,
encoding: str | None = ...,
errors: str = ...,
pax_headers: Mapping[str, str] | None = ...,
debug: int | None = ...,
errorlevel: int | None = ...,
) -> Self: ...
@overload
@classmethod
def open(
cls,
name: StrOrBytesPath | None = None,
*,
mode: Literal["x", "x:", "a", "a:", "w", "w:", "w:tar"],
fileobj: _Fileobj | None = None,
bufsize: int = 10240,
format: int | None = ...,
tarinfo: type[TarInfo] | None = ...,
dereference: bool | None = ...,
ignore_zeros: bool | None = ...,
encoding: str | None = ...,
errors: str = ...,
pax_headers: Mapping[str, str] | None = ...,
debug: int | None = ...,
errorlevel: int | None = ...,
) -> Self: ...
@overload
@classmethod
def open(
cls,
name: StrOrBytesPath | None,
mode: Literal["x:gz", "x:bz2", "w:gz", "w:bz2"],
fileobj: _Fileobj | None = None,
bufsize: int = 10240,
*,
format: int | None = ...,
tarinfo: type[TarInfo] | None = ...,
dereference: bool | None = ...,
ignore_zeros: bool | None = ...,
encoding: str | None = ...,
errors: str = ...,
pax_headers: Mapping[str, str] | None = ...,
debug: int | None = ...,
errorlevel: int | None = ...,
compresslevel: int = 9,
) -> Self: ...
@overload
@classmethod
def open(
cls,
name: StrOrBytesPath | None = None,
*,
mode: Literal["x:gz", "x:bz2", "w:gz", "w:bz2"],
fileobj: _Fileobj | None = None,
bufsize: int = 10240,
format: int | None = ...,
tarinfo: type[TarInfo] | None = ...,
dereference: bool | None = ...,
ignore_zeros: bool | None = ...,
encoding: str | None = ...,
errors: str = ...,
pax_headers: Mapping[str, str] | None = ...,
debug: int | None = ...,
errorlevel: int | None = ...,
compresslevel: int = 9,
) -> Self: ...
@overload
@classmethod
def open(
cls,
name: StrOrBytesPath | None,
mode: Literal["x:xz", "w:xz"],
fileobj: _Fileobj | None = None,
bufsize: int = 10240,
*,
format: int | None = ...,
tarinfo: type[TarInfo] | None = ...,
dereference: bool | None = ...,
ignore_zeros: bool | None = ...,
encoding: str | None = ...,
errors: str = ...,
pax_headers: Mapping[str, str] | None = ...,
debug: int | None = ...,
errorlevel: int | None = ...,
preset: Literal[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] | None = ...,
) -> Self: ...
@overload
@classmethod
def open(
cls,
name: StrOrBytesPath | None = None,
*,
mode: Literal["x:xz", "w:xz"],
fileobj: _Fileobj | None = None,
bufsize: int = 10240,
format: int | None = ...,
tarinfo: type[TarInfo] | None = ...,
dereference: bool | None = ...,
ignore_zeros: bool | None = ...,
encoding: str | None = ...,
errors: str = ...,
pax_headers: Mapping[str, str] | None = ...,
debug: int | None = ...,
errorlevel: int | None = ...,
preset: Literal[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] | None = ...,
) -> Self: ...
@overload
@classmethod
def open(
cls,
name: StrOrBytesPath | ReadableBuffer | None = None,
*,
mode: Literal["r|*", "r|", "r|gz", "r|bz2", "r|xz"],
fileobj: _Fileobj | None = None,
bufsize: int = 10240,
format: int | None = ...,
tarinfo: type[TarInfo] | None = ...,
dereference: bool | None = ...,
ignore_zeros: bool | None = ...,
encoding: str | None = ...,
errors: str = ...,
pax_headers: Mapping[str, str] | None = ...,
debug: int | None = ...,
errorlevel: int | None = ...,
) -> Self: ...
@overload
@classmethod
def open(
cls,
name: StrOrBytesPath | WriteableBuffer | None = None,
*,
mode: Literal["w|", "w|xz"],
fileobj: _Fileobj | None = None,
bufsize: int = 10240,
format: int | None = ...,
tarinfo: type[TarInfo] | None = ...,
dereference: bool | None = ...,
ignore_zeros: bool | None = ...,
encoding: str | None = ...,
errors: str = ...,
pax_headers: Mapping[str, str] | None = ...,
debug: int | None = ...,
errorlevel: int | None = ...,
) -> Self: ...
@overload
@classmethod
def open(
cls,
name: StrOrBytesPath | WriteableBuffer | None = None,
*,
mode: Literal["w|gz", "w|bz2"],
fileobj: _Fileobj | None = None,
bufsize: int = 10240,
format: int | None = ...,
tarinfo: type[TarInfo] | None = ...,
dereference: bool | None = ...,
ignore_zeros: bool | None = ...,
encoding: str | None = ...,
errors: str = ...,
pax_headers: Mapping[str, str] | None = ...,
debug: int | None = ...,
errorlevel: int | None = ...,
compresslevel: int = 9,
) -> Self: ...
@classmethod @classmethod
def taropen( def taropen(
cls, cls,
@ -501,6 +518,8 @@ class TarFile:
) -> TarInfo: ... ) -> TarInfo: ...
def close(self) -> None: ... def close(self) -> None: ...
open = TarFile.open
if sys.version_info >= (3, 9): if sys.version_info >= (3, 9):
def is_tarfile(name: StrOrBytesPath | IO[bytes]) -> bool: ... def is_tarfile(name: StrOrBytesPath | IO[bytes]) -> bool: ...

View file

@ -18,7 +18,7 @@ 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, 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, TypeAliasType, TypeVarTuple, deprecated
__all__ = [ __all__ = [
"FunctionType", "FunctionType",
@ -615,8 +615,27 @@ def prepare_class(
if sys.version_info >= (3, 12): if sys.version_info >= (3, 12):
def get_original_bases(cls: type, /) -> tuple[Any, ...]: ... def get_original_bases(cls: type, /) -> tuple[Any, ...]: ...
# Actually a different type, but `property` is special and we want that too. # Does not actually inherit from property, but saying it does makes sure that
DynamicClassAttribute = property # pyright handles this class correctly.
class DynamicClassAttribute(property):
fget: Callable[[Any], Any] | None
fset: Callable[[Any, Any], object] | None # type: ignore[assignment]
fdel: Callable[[Any], object] | None # type: ignore[assignment]
overwrite_doc: bool
__isabstractmethod__: bool
def __init__(
self,
fget: Callable[[Any], Any] | None = None,
fset: Callable[[Any, Any], object] | None = None,
fdel: Callable[[Any], object] | None = None,
doc: str | None = None,
) -> None: ...
def __get__(self, instance: Any, ownerclass: type | None = None) -> Any: ...
def __set__(self, instance: Any, value: Any) -> None: ...
def __delete__(self, instance: Any) -> None: ...
def getter(self, fget: Callable[[Any], Any]) -> DynamicClassAttribute: ...
def setter(self, fset: Callable[[Any, Any], object]) -> DynamicClassAttribute: ...
def deleter(self, fdel: Callable[[Any], object]) -> DynamicClassAttribute: ...
_Fn = TypeVar("_Fn", bound=Callable[..., object]) _Fn = TypeVar("_Fn", bound=Callable[..., object])
_R = TypeVar("_R") _R = TypeVar("_R")
@ -631,7 +650,7 @@ def coroutine(func: _Fn) -> _Fn: ...
if sys.version_info >= (3, 9): if sys.version_info >= (3, 9):
class GenericAlias: class GenericAlias:
@property @property
def __origin__(self) -> type: ... def __origin__(self) -> type | TypeAliasType: ...
@property @property
def __args__(self) -> tuple[Any, ...]: ... def __args__(self) -> tuple[Any, ...]: ...
@property @property

View file

@ -510,15 +510,15 @@ class Awaitable(Protocol[_T_co]):
def __await__(self) -> Generator[Any, Any, _T_co]: ... def __await__(self) -> Generator[Any, Any, _T_co]: ...
# Non-default variations to accommodate couroutines, and `AwaitableGenerator` having a 4th type parameter. # Non-default variations to accommodate couroutines, and `AwaitableGenerator` having a 4th type parameter.
_SendT_contra_nd = TypeVar("_SendT_contra_nd", contravariant=True) _SendT_nd_contra = TypeVar("_SendT_nd_contra", contravariant=True)
_ReturnT_co_nd = TypeVar("_ReturnT_co_nd", covariant=True) _ReturnT_nd_co = TypeVar("_ReturnT_nd_co", covariant=True)
class Coroutine(Awaitable[_ReturnT_co_nd], Generic[_YieldT_co, _SendT_contra_nd, _ReturnT_co_nd]): class Coroutine(Awaitable[_ReturnT_nd_co], Generic[_YieldT_co, _SendT_nd_contra, _ReturnT_nd_co]):
__name__: str __name__: str
__qualname__: str __qualname__: str
@abstractmethod @abstractmethod
def send(self, value: _SendT_contra_nd, /) -> _YieldT_co: ... def send(self, value: _SendT_nd_contra, /) -> _YieldT_co: ...
@overload @overload
@abstractmethod @abstractmethod
def throw( def throw(
@ -534,9 +534,9 @@ class Coroutine(Awaitable[_ReturnT_co_nd], Generic[_YieldT_co, _SendT_contra_nd,
# 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_nd], Awaitable[_ReturnT_nd_co],
Generator[_YieldT_co, _SendT_contra_nd, _ReturnT_co_nd], Generator[_YieldT_co, _SendT_nd_contra, _ReturnT_nd_co],
Generic[_YieldT_co, _SendT_contra_nd, _ReturnT_co_nd, _S], Generic[_YieldT_co, _SendT_nd_contra, _ReturnT_nd_co, _S],
metaclass=ABCMeta, metaclass=ABCMeta,
): ... ): ...

View file

@ -1,5 +1,3 @@
# Since this module defines "Self" it is not recognized by Ruff as typing_extensions.Self
# ruff: noqa: PYI034
import abc import abc
import sys import sys
import typing import typing
@ -251,6 +249,7 @@ class _TypedDict(Mapping[str, object], metaclass=abc.ABCMeta):
@overload @overload
def __ror__(self, value: dict[str, Any], /) -> dict[str, object]: ... def __ror__(self, value: dict[str, Any], /) -> dict[str, object]: ...
# supposedly incompatible definitions of `__ior__` and `__or__`: # supposedly incompatible definitions of `__ior__` and `__or__`:
# Since this module defines "Self" it is not recognized by Ruff as typing_extensions.Self
def __ior__(self, value: Self, /) -> Self: ... # type: ignore[misc] def __ior__(self, value: Self, /) -> Self: ... # type: ignore[misc]
OrderedDict = _Alias() OrderedDict = _Alias()

View file

@ -20,7 +20,7 @@ from typing import (
TypeVar, TypeVar,
overload, overload,
) )
from typing_extensions import ParamSpec, Self, TypeAlias from typing_extensions import Never, ParamSpec, Self, TypeAlias
from warnings import WarningMessage from warnings import WarningMessage
if sys.version_info >= (3, 9): if sys.version_info >= (3, 9):
@ -323,6 +323,10 @@ class TestCase:
self, subset: Mapping[Any, Any], dictionary: Mapping[Any, Any], msg: object = None self, subset: Mapping[Any, Any], dictionary: Mapping[Any, Any], msg: object = None
) -> None: ... ) -> None: ...
if sys.version_info >= (3, 10):
# Runtime has *args, **kwargs, but will error if any are supplied
def __init_subclass__(cls, *args: Never, **kwargs: Never) -> None: ...
class FunctionTestCase(TestCase): class FunctionTestCase(TestCase):
def __init__( def __init__(
self, self,

View file

@ -362,14 +362,6 @@ else:
def joinpath(self, *other: StrPath) -> Path: ... def joinpath(self, *other: StrPath) -> Path: ...
else: else:
def joinpath(self, add: StrPath) -> Path: ... # undocumented def joinpath(self, add: StrPath) -> Path: ... # undocumented
if sys.version_info >= (3, 12):
def glob(self, pattern: str) -> Iterator[Self]: ...
def rglob(self, pattern: str) -> Iterator[Self]: ...
def is_symlink(self) -> Literal[False]: ...
def relative_to(self, other: Path, *extra: StrPath) -> str: ...
def match(self, path_pattern: str) -> bool: ...
def __eq__(self, other: object) -> bool: ...
def __hash__(self) -> int: ...
def __truediv__(self, add: StrPath) -> Path: ... def __truediv__(self, add: StrPath) -> Path: ...

View file

@ -4,11 +4,9 @@ from collections.abc import Iterator, Sequence
from io import TextIOWrapper from io import TextIOWrapper
from os import PathLike from os import PathLike
from typing import IO, Literal, TypeVar, overload from typing import IO, Literal, TypeVar, overload
from typing_extensions import Self, TypeAlias from typing_extensions import Self
from zipfile import ZipFile from zipfile import ZipFile
_ReadWriteBinaryMode: TypeAlias = Literal["r", "w", "rb", "wb"]
_ZF = TypeVar("_ZF", bound=ZipFile) _ZF = TypeVar("_ZF", bound=ZipFile)
if sys.version_info >= (3, 12): if sys.version_info >= (3, 12):
@ -39,42 +37,29 @@ if sys.version_info >= (3, 12):
def name(self) -> str: ... def name(self) -> str: ...
@property @property
def parent(self) -> PathLike[str]: ... # undocumented def parent(self) -> PathLike[str]: ... # undocumented
if sys.version_info >= (3, 10): @property
@property def filename(self) -> PathLike[str]: ... # undocumented
def filename(self) -> PathLike[str]: ... # undocumented @property
if sys.version_info >= (3, 11): def suffix(self) -> str: ...
@property @property
def suffix(self) -> str: ... def suffixes(self) -> list[str]: ...
@property @property
def suffixes(self) -> list[str]: ... def stem(self) -> str: ...
@property @overload
def stem(self) -> str: ... def open(
self,
if sys.version_info >= (3, 9): mode: Literal["r", "w"] = "r",
@overload encoding: str | None = None,
def open( errors: str | None = None,
self, newline: str | None = None,
mode: Literal["r", "w"] = "r", line_buffering: bool = ...,
encoding: str | None = None, write_through: bool = ...,
errors: str | None = None, *,
newline: str | None = None, pwd: bytes | None = None,
line_buffering: bool = ..., ) -> TextIOWrapper: ...
write_through: bool = ..., @overload
*, def open(self, mode: Literal["rb", "wb"], *, pwd: bytes | None = None) -> IO[bytes]: ...
pwd: bytes | None = None, def iterdir(self) -> Iterator[Self]: ...
) -> TextIOWrapper: ...
@overload
def open(self, mode: Literal["rb", "wb"], *, pwd: bytes | None = None) -> IO[bytes]: ...
else:
def open(
self, mode: _ReadWriteBinaryMode = "r", pwd: bytes | None = None, *, force_zip64: bool = False
) -> IO[bytes]: ...
if sys.version_info >= (3, 10):
def iterdir(self) -> Iterator[Self]: ...
else:
def iterdir(self) -> Iterator[Path]: ...
def is_dir(self) -> bool: ... def is_dir(self) -> bool: ...
def is_file(self) -> bool: ... def is_file(self) -> bool: ...
def exists(self) -> bool: ... def exists(self) -> bool: ...
@ -87,17 +72,12 @@ if sys.version_info >= (3, 12):
write_through: bool = ..., write_through: bool = ...,
) -> str: ... ) -> str: ...
def read_bytes(self) -> bytes: ... def read_bytes(self) -> bytes: ...
if sys.version_info >= (3, 10): def joinpath(self, *other: StrPath) -> Path: ...
def joinpath(self, *other: StrPath) -> Path: ... def glob(self, pattern: str) -> Iterator[Self]: ...
else: def rglob(self, pattern: str) -> Iterator[Self]: ...
def joinpath(self, add: StrPath) -> Path: ... # undocumented def is_symlink(self) -> Literal[False]: ...
if sys.version_info >= (3, 12): def relative_to(self, other: Path, *extra: StrPath) -> str: ...
def glob(self, pattern: str) -> Iterator[Self]: ... def match(self, path_pattern: str) -> bool: ...
def rglob(self, pattern: str) -> Iterator[Self]: ... def __eq__(self, other: object) -> bool: ...
def is_symlink(self) -> Literal[False]: ... def __hash__(self) -> int: ...
def relative_to(self, other: Path, *extra: StrPath) -> str: ...
def match(self, path_pattern: str) -> bool: ...
def __eq__(self, other: object) -> bool: ...
def __hash__(self) -> int: ...
def __truediv__(self, add: StrPath) -> Path: ... def __truediv__(self, add: StrPath) -> Path: ...