diff --git a/stdlib/_decimal.pyi b/stdlib/_decimal.pyi index 5924c36a37ff..3f997e7d9a37 100644 --- a/stdlib/_decimal.pyi +++ b/stdlib/_decimal.pyi @@ -1,10 +1,9 @@ import numbers import sys -from _typeshed import Self from collections.abc import Container, Sequence from types import TracebackType from typing import Any, ClassVar, NamedTuple, overload -from typing_extensions import Literal, TypeAlias +from typing_extensions import Literal, Self, TypeAlias _Decimal: TypeAlias = Decimal | int _DecimalNew: TypeAlias = Decimal | float | str | tuple[int, Sequence[int], int] @@ -69,9 +68,9 @@ else: def localcontext(ctx: Context | None = None) -> _ContextManager: ... class Decimal: - def __new__(cls: type[Self], value: _DecimalNew = ..., context: Context | None = ...) -> Self: ... + def __new__(cls, value: _DecimalNew = ..., context: Context | None = ...) -> Self: ... @classmethod - def from_float(cls: type[Self], __f: float) -> Self: ... + def from_float(cls, __f: float) -> Self: ... def __bool__(self) -> bool: ... def compare(self, other: _Decimal, context: Context | None = None) -> Decimal: ... def as_tuple(self) -> DecimalTuple: ... @@ -163,9 +162,9 @@ class Decimal: def rotate(self, other: _Decimal, context: Context | None = None) -> Decimal: ... def scaleb(self, other: _Decimal, context: Context | None = None) -> Decimal: ... def shift(self, other: _Decimal, context: Context | None = None) -> Decimal: ... - def __reduce__(self: Self) -> tuple[type[Self], tuple[str]]: ... - def __copy__(self: Self) -> Self: ... - def __deepcopy__(self: Self, __memo: Any) -> Self: ... + def __reduce__(self) -> tuple[type[Self], tuple[str]]: ... + def __copy__(self) -> Self: ... + def __deepcopy__(self, __memo: Any) -> Self: ... def __format__(self, __specifier: str, __context: Context | None = ...) -> str: ... class _ContextManager: @@ -203,7 +202,7 @@ class Context: traps: None | dict[_TrapType, bool] | Container[_TrapType] = ..., _ignored_flags: list[_TrapType] | None = ..., ) -> None: ... - def __reduce__(self: Self) -> tuple[type[Self], tuple[Any, ...]]: ... + def __reduce__(self) -> tuple[type[Self], tuple[Any, ...]]: ... def clear_flags(self) -> None: ... def clear_traps(self) -> None: ... def copy(self) -> Context: ... diff --git a/stdlib/_py_abc.pyi b/stdlib/_py_abc.pyi index ddf04364a238..cc45c6ad3814 100644 --- a/stdlib/_py_abc.pyi +++ b/stdlib/_py_abc.pyi @@ -1,4 +1,4 @@ -from _typeshed import Self +import _typeshed from typing import Any, NewType, TypeVar _T = TypeVar("_T") @@ -8,5 +8,7 @@ _CacheToken = NewType("_CacheToken", int) def get_cache_token() -> _CacheToken: ... class ABCMeta(type): - def __new__(__mcls: type[Self], __name: str, __bases: tuple[type[Any], ...], __namespace: dict[str, Any]) -> Self: ... + def __new__( + __mcls: type[_typeshed.Self], __name: str, __bases: tuple[type[Any], ...], __namespace: dict[str, Any] + ) -> _typeshed.Self: ... def register(cls, subclass: type[_T]) -> type[_T]: ... diff --git a/stdlib/_weakref.pyi b/stdlib/_weakref.pyi index df462ad859c7..2a43de3ffd6b 100644 --- a/stdlib/_weakref.pyi +++ b/stdlib/_weakref.pyi @@ -1,8 +1,7 @@ import sys -from _typeshed import Self from collections.abc import Callable from typing import Any, Generic, TypeVar, overload -from typing_extensions import final +from typing_extensions import Self, final if sys.version_info >= (3, 9): from types import GenericAlias @@ -21,7 +20,7 @@ class ProxyType(Generic[_T]): # "weakproxy" class ReferenceType(Generic[_T]): __callback__: Callable[[ReferenceType[_T]], Any] - def __new__(cls: type[Self], o: _T, callback: Callable[[ReferenceType[_T]], Any] | None = ...) -> Self: ... + def __new__(cls, o: _T, callback: Callable[[ReferenceType[_T]], Any] | None = ...) -> Self: ... def __call__(self) -> _T | None: ... if sys.version_info >= (3, 9): def __class_getitem__(cls, item: Any) -> GenericAlias: ... diff --git a/stdlib/_weakrefset.pyi b/stdlib/_weakrefset.pyi index fdf26641bbeb..d73d79155329 100644 --- a/stdlib/_weakrefset.pyi +++ b/stdlib/_weakrefset.pyi @@ -1,7 +1,7 @@ import sys -from _typeshed import Self from collections.abc import Iterable, Iterator, MutableSet from typing import Any, Generic, TypeVar, overload +from typing_extensions import Self if sys.version_info >= (3, 9): from types import GenericAlias @@ -18,21 +18,21 @@ class WeakSet(MutableSet[_T], Generic[_T]): def __init__(self, data: Iterable[_T]) -> None: ... def add(self, item: _T) -> None: ... def discard(self, item: _T) -> None: ... - def copy(self: Self) -> Self: ... + def copy(self) -> Self: ... def remove(self, item: _T) -> None: ... def update(self, other: Iterable[_T]) -> None: ... def __contains__(self, item: object) -> bool: ... def __len__(self) -> int: ... def __iter__(self) -> Iterator[_T]: ... - def __ior__(self: Self, other: Iterable[_T]) -> Self: ... # type: ignore[override,misc] - def difference(self: Self, other: Iterable[_T]) -> Self: ... - def __sub__(self: Self, other: Iterable[Any]) -> Self: ... + def __ior__(self, other: Iterable[_T]) -> Self: ... # type: ignore[override,misc] + def difference(self, other: Iterable[_T]) -> Self: ... + def __sub__(self, other: Iterable[Any]) -> Self: ... def difference_update(self, other: Iterable[Any]) -> None: ... - def __isub__(self: Self, other: Iterable[Any]) -> Self: ... - def intersection(self: Self, other: Iterable[_T]) -> Self: ... - def __and__(self: Self, other: Iterable[Any]) -> Self: ... + def __isub__(self, other: Iterable[Any]) -> Self: ... + def intersection(self, other: Iterable[_T]) -> Self: ... + def __and__(self, other: Iterable[Any]) -> Self: ... def intersection_update(self, other: Iterable[Any]) -> None: ... - def __iand__(self: Self, other: Iterable[Any]) -> Self: ... + def __iand__(self, other: Iterable[Any]) -> Self: ... def issubset(self, other: Iterable[_T]) -> bool: ... def __le__(self, other: Iterable[_T]) -> bool: ... def __lt__(self, other: Iterable[_T]) -> bool: ... @@ -43,7 +43,7 @@ class WeakSet(MutableSet[_T], Generic[_T]): def symmetric_difference(self, other: Iterable[_S]) -> WeakSet[_S | _T]: ... def __xor__(self, other: Iterable[_S]) -> WeakSet[_S | _T]: ... def symmetric_difference_update(self, other: Iterable[_T]) -> None: ... - def __ixor__(self: Self, other: Iterable[_T]) -> Self: ... # type: ignore[override,misc] + def __ixor__(self, other: Iterable[_T]) -> Self: ... # type: ignore[override,misc] def union(self, other: Iterable[_S]) -> WeakSet[_S | _T]: ... def __or__(self, other: Iterable[_S]) -> WeakSet[_S | _T]: ... def isdisjoint(self, other: Iterable[_T]) -> bool: ... diff --git a/stdlib/abc.pyi b/stdlib/abc.pyi index 44a5b2289832..068dab4752be 100644 --- a/stdlib/abc.pyi +++ b/stdlib/abc.pyi @@ -1,5 +1,6 @@ +import _typeshed import sys -from _typeshed import Self, SupportsWrite +from _typeshed import SupportsWrite from collections.abc import Callable from typing import Any, Generic, TypeVar from typing_extensions import Literal @@ -13,10 +14,12 @@ class ABCMeta(type): __abstractmethods__: frozenset[str] if sys.version_info >= (3, 11): def __new__( - __mcls: type[Self], __name: str, __bases: tuple[type, ...], __namespace: dict[str, Any], **kwargs: Any - ) -> Self: ... + __mcls: type[_typeshed.Self], __name: str, __bases: tuple[type, ...], __namespace: dict[str, Any], **kwargs: Any + ) -> _typeshed.Self: ... else: - def __new__(mcls: type[Self], name: str, bases: tuple[type, ...], namespace: dict[str, Any], **kwargs: Any) -> Self: ... + def __new__( + mcls: type[_typeshed.Self], name: str, bases: tuple[type, ...], namespace: dict[str, Any], **kwargs: Any + ) -> _typeshed.Self: ... def __instancecheck__(cls: ABCMeta, instance: Any) -> bool: ... def __subclasscheck__(cls: ABCMeta, subclass: type) -> bool: ... diff --git a/stdlib/aifc.pyi b/stdlib/aifc.pyi index ad126d6cdbef..ab0c18ed6623 100644 --- a/stdlib/aifc.pyi +++ b/stdlib/aifc.pyi @@ -1,8 +1,7 @@ import sys -from _typeshed import Self from types import TracebackType from typing import IO, Any, NamedTuple, overload -from typing_extensions import Literal, TypeAlias +from typing_extensions import Literal, Self, TypeAlias if sys.version_info >= (3, 9): __all__ = ["Error", "open"] @@ -24,7 +23,7 @@ _Marker: TypeAlias = tuple[int, int, bytes] class Aifc_read: def __init__(self, f: _File) -> None: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__( self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None ) -> None: ... @@ -48,7 +47,7 @@ class Aifc_read: class Aifc_write: def __init__(self, f: _File) -> None: ... def __del__(self) -> None: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__( self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None ) -> None: ... diff --git a/stdlib/array.pyi b/stdlib/array.pyi index 25c389c47e8e..827bbb97897f 100644 --- a/stdlib/array.pyi +++ b/stdlib/array.pyi @@ -1,10 +1,10 @@ import sys -from _typeshed import ReadableBuffer, Self, SupportsRead, SupportsWrite +from _typeshed import ReadableBuffer, SupportsRead, SupportsWrite from collections.abc import Iterable # pytype crashes if array inherits from collections.abc.MutableSequence instead of typing.MutableSequence from typing import Any, Generic, MutableSequence, TypeVar, overload # noqa: Y022 -from typing_extensions import Literal, SupportsIndex, TypeAlias +from typing_extensions import Literal, Self, SupportsIndex, TypeAlias _IntTypeCode: TypeAlias = Literal["b", "B", "h", "H", "i", "I", "l", "L", "q", "Q"] _FloatTypeCode: TypeAlias = Literal["f", "d"] @@ -72,8 +72,8 @@ class array(MutableSequence[_T], Generic[_T]): def __add__(self, __x: array[_T]) -> array[_T]: ... def __ge__(self, __other: array[_T]) -> bool: ... def __gt__(self, __other: array[_T]) -> bool: ... - def __iadd__(self: Self, __x: array[_T]) -> Self: ... # type: ignore[override] - def __imul__(self: Self, __n: int) -> Self: ... + def __iadd__(self, __x: array[_T]) -> Self: ... # type: ignore[override] + def __imul__(self, __n: int) -> Self: ... def __le__(self, __other: array[_T]) -> bool: ... def __lt__(self, __other: array[_T]) -> bool: ... def __mul__(self, __n: int) -> array[_T]: ... diff --git a/stdlib/asyncio/events.pyi b/stdlib/asyncio/events.pyi index 92e455a25f78..f97afe873c9f 100644 --- a/stdlib/asyncio/events.pyi +++ b/stdlib/asyncio/events.pyi @@ -1,12 +1,12 @@ import ssl import sys -from _typeshed import FileDescriptorLike, ReadableBuffer, Self, StrPath, Unused, WriteableBuffer +from _typeshed import FileDescriptorLike, ReadableBuffer, StrPath, Unused, WriteableBuffer from abc import ABCMeta, abstractmethod from collections.abc import Awaitable, Callable, Coroutine, Generator, Sequence from contextvars import Context from socket import AddressFamily, SocketKind, _Address, _RetAddress, socket from typing import IO, Any, Protocol, TypeVar, overload -from typing_extensions import Literal, TypeAlias +from typing_extensions import Literal, Self, TypeAlias from .base_events import Server from .futures import Future @@ -95,7 +95,7 @@ class TimerHandle(Handle): class AbstractServer: @abstractmethod def close(self) -> None: ... - async def __aenter__(self: Self) -> Self: ... + async def __aenter__(self) -> Self: ... async def __aexit__(self, *exc: Unused) -> None: ... @abstractmethod def get_loop(self) -> AbstractEventLoop: ... diff --git a/stdlib/asyncio/futures.pyi b/stdlib/asyncio/futures.pyi index f325272d2403..79209f5ed4fb 100644 --- a/stdlib/asyncio/futures.pyi +++ b/stdlib/asyncio/futures.pyi @@ -1,9 +1,8 @@ import sys -from _typeshed import Self from collections.abc import Awaitable, Callable, Generator, Iterable from concurrent.futures._base import Error, Future as _ConcurrentFuture from typing import Any, TypeVar -from typing_extensions import Literal, TypeGuard +from typing_extensions import Literal, Self, TypeGuard from .events import AbstractEventLoop @@ -43,8 +42,8 @@ class Future(Awaitable[_T], Iterable[_T]): def __del__(self) -> None: ... def get_loop(self) -> AbstractEventLoop: ... @property - def _callbacks(self: Self) -> list[tuple[Callable[[Self], Any], Context]]: ... - def add_done_callback(self: Self, __fn: Callable[[Self], object], *, context: Context | None = None) -> None: ... + def _callbacks(self) -> list[tuple[Callable[[Self], Any], Context]]: ... + def add_done_callback(self, __fn: Callable[[Self], object], *, context: Context | None = None) -> None: ... if sys.version_info >= (3, 9): def cancel(self, msg: Any | None = None) -> bool: ... else: @@ -54,7 +53,7 @@ class Future(Awaitable[_T], Iterable[_T]): def done(self) -> bool: ... def result(self) -> _T: ... def exception(self) -> BaseException | None: ... - def remove_done_callback(self: Self, __fn: Callable[[Self], object]) -> int: ... + def remove_done_callback(self, __fn: Callable[[Self], object]) -> int: ... def set_result(self, __result: _T) -> None: ... def set_exception(self, __exception: type | BaseException) -> None: ... def __iter__(self) -> Generator[Any, None, _T]: ... diff --git a/stdlib/asyncio/locks.pyi b/stdlib/asyncio/locks.pyi index 87bcaa2110db..ab4e63ab59b1 100644 --- a/stdlib/asyncio/locks.pyi +++ b/stdlib/asyncio/locks.pyi @@ -1,11 +1,11 @@ import enum import sys -from _typeshed import Self, Unused +from _typeshed import Unused from collections import deque from collections.abc import Callable, Generator from types import TracebackType from typing import Any, TypeVar -from typing_extensions import Literal +from typing_extensions import Literal, Self from .events import AbstractEventLoop from .futures import Future @@ -103,7 +103,7 @@ if sys.version_info >= (3, 11): class Barrier(_LoopBoundMixin): def __init__(self, parties: int) -> None: ... - async def __aenter__(self: Self) -> Self: ... + async def __aenter__(self) -> Self: ... async def __aexit__(self, *args: Unused) -> None: ... async def wait(self) -> int: ... async def abort(self) -> None: ... diff --git a/stdlib/asyncio/runners.pyi b/stdlib/asyncio/runners.pyi index 484f9eb831a1..847072b633ac 100644 --- a/stdlib/asyncio/runners.pyi +++ b/stdlib/asyncio/runners.pyi @@ -1,9 +1,9 @@ import sys -from _typeshed import Self, Unused +from _typeshed import Unused from collections.abc import Callable, Coroutine from contextvars import Context from typing import Any, TypeVar -from typing_extensions import final +from typing_extensions import Self, final from .events import AbstractEventLoop @@ -17,7 +17,7 @@ if sys.version_info >= (3, 11): @final class Runner: def __init__(self, *, debug: bool | None = None, loop_factory: Callable[[], AbstractEventLoop] | None = None) -> None: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__(self, exc_type: Unused, exc_val: Unused, exc_tb: Unused) -> None: ... def close(self) -> None: ... def get_loop(self) -> AbstractEventLoop: ... diff --git a/stdlib/asyncio/streams.pyi b/stdlib/asyncio/streams.pyi index 2468f482291c..f30c57305d93 100644 --- a/stdlib/asyncio/streams.pyi +++ b/stdlib/asyncio/streams.pyi @@ -1,9 +1,9 @@ import ssl import sys -from _typeshed import Self, StrPath +from _typeshed import StrPath from collections.abc import AsyncIterator, Awaitable, Callable, Iterable, Sequence from typing import Any -from typing_extensions import SupportsIndex, TypeAlias +from typing_extensions import Self, SupportsIndex, TypeAlias from . import events, protocols, transports from .base_events import Server @@ -166,5 +166,5 @@ class StreamReader(AsyncIterator[bytes]): async def readuntil(self, separator: bytes | bytearray | memoryview = b"\n") -> bytes: ... async def read(self, n: int = -1) -> bytes: ... async def readexactly(self, n: int) -> bytes: ... - def __aiter__(self: Self) -> Self: ... + def __aiter__(self) -> Self: ... async def __anext__(self) -> bytes: ... diff --git a/stdlib/asyncio/taskgroups.pyi b/stdlib/asyncio/taskgroups.pyi index 9e6c6e047368..8daa96f1ede0 100644 --- a/stdlib/asyncio/taskgroups.pyi +++ b/stdlib/asyncio/taskgroups.pyi @@ -1,10 +1,10 @@ # This only exists in 3.11+. See VERSIONS. -from _typeshed import Self from collections.abc import Coroutine, Generator from contextvars import Context from types import TracebackType from typing import Any, TypeVar +from typing_extensions import Self from .tasks import Task @@ -13,7 +13,7 @@ __all__ = ["TaskGroup"] _T = TypeVar("_T") class TaskGroup: - async def __aenter__(self: Self) -> Self: ... + async def __aenter__(self) -> Self: ... async def __aexit__(self, et: type[BaseException] | None, exc: BaseException | None, tb: TracebackType | None) -> None: ... def create_task( self, coro: Generator[Any, None, _T] | Coroutine[Any, Any, _T], *, name: str | None = None, context: Context | None = None diff --git a/stdlib/asyncio/timeouts.pyi b/stdlib/asyncio/timeouts.pyi index be516b5851d1..2d31b777b77d 100644 --- a/stdlib/asyncio/timeouts.pyi +++ b/stdlib/asyncio/timeouts.pyi @@ -1,6 +1,5 @@ -from _typeshed import Self from types import TracebackType -from typing_extensions import final +from typing_extensions import Self, final __all__ = ("Timeout", "timeout", "timeout_at") @@ -10,7 +9,7 @@ class Timeout: def when(self) -> float | None: ... def reschedule(self, when: float | None) -> None: ... def expired(self) -> bool: ... - async def __aenter__(self: Self) -> Self: ... + async def __aenter__(self) -> Self: ... async def __aexit__( self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None ) -> None: ... diff --git a/stdlib/asyncio/unix_events.pyi b/stdlib/asyncio/unix_events.pyi index 5e2b05f57ef1..e28d64b5287b 100644 --- a/stdlib/asyncio/unix_events.pyi +++ b/stdlib/asyncio/unix_events.pyi @@ -1,10 +1,9 @@ import sys import types -from _typeshed import Self from abc import ABCMeta, abstractmethod from collections.abc import Callable from typing import Any -from typing_extensions import Literal +from typing_extensions import Literal, Self from .events import AbstractEventLoop, BaseDefaultEventLoopPolicy from .selector_events import BaseSelectorEventLoop @@ -22,7 +21,7 @@ class AbstractChildWatcher: @abstractmethod def close(self) -> None: ... @abstractmethod - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... @abstractmethod def __exit__(self, typ: type[BaseException] | None, exc: BaseException | None, tb: types.TracebackType | None) -> None: ... if sys.version_info >= (3, 8): @@ -64,13 +63,13 @@ if sys.platform != "win32": def attach_loop(self, loop: AbstractEventLoop | None) -> None: ... class SafeChildWatcher(BaseChildWatcher): - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__(self, a: type[BaseException] | None, b: BaseException | None, c: types.TracebackType | None) -> None: ... def add_child_handler(self, pid: int, callback: Callable[..., object], *args: Any) -> None: ... def remove_child_handler(self, pid: int) -> bool: ... class FastChildWatcher(BaseChildWatcher): - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__(self, a: type[BaseException] | None, b: BaseException | None, c: types.TracebackType | None) -> None: ... def add_child_handler(self, pid: int, callback: Callable[..., object], *args: Any) -> None: ... def remove_child_handler(self, pid: int) -> bool: ... @@ -95,7 +94,7 @@ if sys.platform != "win32": class MultiLoopChildWatcher(AbstractChildWatcher): def is_active(self) -> bool: ... def close(self) -> None: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__( self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: types.TracebackType | None ) -> None: ... @@ -106,7 +105,7 @@ if sys.platform != "win32": class ThreadedChildWatcher(AbstractChildWatcher): def is_active(self) -> Literal[True]: ... def close(self) -> None: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__( self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: types.TracebackType | None ) -> None: ... @@ -117,7 +116,7 @@ if sys.platform != "win32": if sys.version_info >= (3, 9): class PidfdChildWatcher(AbstractChildWatcher): - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__( self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: types.TracebackType | None ) -> None: ... diff --git a/stdlib/asyncio/windows_utils.pyi b/stdlib/asyncio/windows_utils.pyi index 6ac4e0d89aa4..f3a82e2b8462 100644 --- a/stdlib/asyncio/windows_utils.pyi +++ b/stdlib/asyncio/windows_utils.pyi @@ -1,10 +1,9 @@ import subprocess import sys -from _typeshed import Self from collections.abc import Callable from types import TracebackType from typing import Any, AnyStr, Protocol -from typing_extensions import Literal +from typing_extensions import Literal, Self if sys.platform == "win32": __all__ = ("pipe", "Popen", "PIPE", "PipeHandle") @@ -25,7 +24,7 @@ if sys.platform == "win32": else: def __del__(self) -> None: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__(self, t: type[BaseException] | None, v: BaseException | None, tb: TracebackType | None) -> None: ... @property def handle(self) -> int: ... @@ -41,7 +40,7 @@ if sys.platform == "win32": # subprocess.Popen takes other positional-or-keyword arguments before # stdin. def __new__( - cls: type[Self], + cls, args: subprocess._CMD, stdin: subprocess._FILE | None = ..., stdout: subprocess._FILE | None = ..., diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index 1d3bb6abdcb6..66856d90a454 100644 --- a/stdlib/builtins.pyi +++ b/stdlib/builtins.pyi @@ -1,4 +1,5 @@ import _ast +import _typeshed import sys import types from _collections_abc import dict_items, dict_keys, dict_values @@ -11,7 +12,6 @@ from _typeshed import ( OpenBinaryModeWriting, OpenTextMode, ReadableBuffer, - Self, SupportsAdd, SupportsAiter, SupportsAnext, @@ -54,7 +54,7 @@ from typing import ( # noqa: Y022 overload, type_check_only, ) -from typing_extensions import Literal, LiteralString, SupportsIndex, TypeAlias, TypeGuard, final +from typing_extensions import Literal, LiteralString, Self, SupportsIndex, TypeAlias, TypeGuard, final if sys.version_info >= (3, 9): from types import GenericAlias @@ -82,12 +82,12 @@ class object: __module__: str __annotations__: dict[str, Any] @property - def __class__(self: Self) -> type[Self]: ... + def __class__(self) -> type[Self]: ... # Ignore errors about type mismatch between property getter and setter @__class__.setter def __class__(self, __type: type[object]) -> None: ... # noqa: F811 def __init__(self) -> None: ... - def __new__(cls: type[Self]) -> Self: ... + def __new__(cls) -> Self: ... # N.B. `object.__setattr__` and `object.__delattr__` are heavily special-cased by type checkers. # Overriding them in subclasses has different semantics, even if the override has an identical signature. def __setattr__(self, __name: str, __value: Any) -> None: ... @@ -168,9 +168,11 @@ class type: @overload def __new__(cls, __o: object) -> type: ... @overload - def __new__(cls: type[Self], __name: str, __bases: tuple[type, ...], __namespace: dict[str, Any], **kwds: Any) -> Self: ... + def __new__( + cls: type[_typeshed.Self], __name: str, __bases: tuple[type, ...], __namespace: dict[str, Any], **kwds: Any + ) -> _typeshed.Self: ... def __call__(self, *args: Any, **kwds: Any) -> Any: ... - def __subclasses__(self: Self) -> list[Self]: ... + def __subclasses__(self: _typeshed.Self) -> list[_typeshed.Self]: ... # Note: the documentation doesn't specify what the return type is, the standard # implementation seems to be returning a list. def mro(self) -> list[type]: ... @@ -196,9 +198,9 @@ _LiteralInteger = _PositiveInteger | _NegativeInteger | Literal[0] # noqa: Y026 class int: @overload - def __new__(cls: type[Self], __x: str | ReadableBuffer | SupportsInt | SupportsIndex | SupportsTrunc = ...) -> Self: ... + def __new__(cls, __x: str | ReadableBuffer | SupportsInt | SupportsIndex | SupportsTrunc = ...) -> Self: ... @overload - def __new__(cls: type[Self], __x: str | bytes | bytearray, base: SupportsIndex) -> Self: ... + def __new__(cls, __x: str | bytes | bytearray, base: SupportsIndex) -> Self: ... if sys.version_info >= (3, 8): def as_integer_ratio(self) -> tuple[int, Literal[1]]: ... @@ -221,7 +223,7 @@ class int: ) -> bytes: ... @classmethod def from_bytes( - cls: type[Self], + cls, bytes: Iterable[SupportsIndex] | SupportsBytes | ReadableBuffer, byteorder: Literal["little", "big"] = "big", *, @@ -231,7 +233,7 @@ class int: def to_bytes(self, length: SupportsIndex, byteorder: Literal["little", "big"], *, signed: bool = False) -> bytes: ... @classmethod def from_bytes( - cls: type[Self], + cls, bytes: Iterable[SupportsIndex] | SupportsBytes | ReadableBuffer, byteorder: Literal["little", "big"], *, @@ -298,12 +300,12 @@ class int: def __index__(self) -> int: ... class float: - def __new__(cls: type[Self], __x: SupportsFloat | SupportsIndex | str | ReadableBuffer = ...) -> Self: ... + def __new__(cls, __x: SupportsFloat | SupportsIndex | str | ReadableBuffer = ...) -> Self: ... def as_integer_ratio(self) -> tuple[int, int]: ... def hex(self) -> str: ... def is_integer(self) -> bool: ... @classmethod - def fromhex(cls: type[Self], __s: str) -> Self: ... + def fromhex(cls, __s: str) -> Self: ... @property def real(self) -> float: ... @property @@ -364,19 +366,17 @@ class complex: # Python doesn't currently accept SupportsComplex for the second argument @overload def __new__( - cls: type[Self], + cls, real: complex | SupportsComplex | SupportsFloat | SupportsIndex = ..., imag: complex | SupportsFloat | SupportsIndex = ..., ) -> Self: ... @overload - def __new__(cls: type[Self], real: str | SupportsComplex | SupportsFloat | SupportsIndex | complex) -> Self: ... + def __new__(cls, real: str | SupportsComplex | SupportsFloat | SupportsIndex | complex) -> Self: ... else: @overload - def __new__( - cls: type[Self], real: complex | SupportsComplex | SupportsFloat = ..., imag: complex | SupportsFloat = ... - ) -> Self: ... + def __new__(cls, real: complex | SupportsComplex | SupportsFloat = ..., imag: complex | SupportsFloat = ...) -> Self: ... @overload - def __new__(cls: type[Self], real: str | SupportsComplex | SupportsFloat | complex) -> Self: ... + def __new__(cls, real: str | SupportsComplex | SupportsFloat | complex) -> Self: ... @property def real(self) -> float: ... @@ -410,9 +410,9 @@ class _TranslateTable(Protocol): class str(Sequence[str]): @overload - def __new__(cls: type[Self], object: object = ...) -> Self: ... + def __new__(cls, object: object = ...) -> Self: ... @overload - def __new__(cls: type[Self], object: ReadableBuffer, encoding: str = ..., errors: str = ...) -> Self: ... + def __new__(cls, object: ReadableBuffer, encoding: str = ..., errors: str = ...) -> Self: ... @overload def capitalize(self: LiteralString) -> LiteralString: ... @overload @@ -589,11 +589,11 @@ class str(Sequence[str]): class bytes(ByteString): @overload - def __new__(cls: type[Self], __o: Iterable[SupportsIndex] | SupportsIndex | SupportsBytes | ReadableBuffer) -> Self: ... + def __new__(cls, __o: Iterable[SupportsIndex] | SupportsIndex | SupportsBytes | ReadableBuffer) -> Self: ... @overload - def __new__(cls: type[Self], __string: str, encoding: str, errors: str = ...) -> Self: ... + def __new__(cls, __string: str, encoding: str, errors: str = ...) -> Self: ... @overload - def __new__(cls: type[Self]) -> Self: ... + def __new__(cls) -> Self: ... def capitalize(self) -> bytes: ... def center(self, __width: SupportsIndex, __fillchar: bytes = b" ") -> bytes: ... def count( @@ -665,7 +665,7 @@ class bytes(ByteString): def upper(self) -> bytes: ... def zfill(self, __width: SupportsIndex) -> bytes: ... @classmethod - def fromhex(cls: type[Self], __s: str) -> Self: ... + def fromhex(cls, __s: str) -> Self: ... @staticmethod def maketrans(__frm: ReadableBuffer, __to: ReadableBuffer) -> bytes: ... def __len__(self) -> int: ... @@ -774,7 +774,7 @@ class bytearray(MutableSequence[int], ByteString): def upper(self) -> bytearray: ... def zfill(self, __width: SupportsIndex) -> bytearray: ... @classmethod - def fromhex(cls: type[Self], __string: str) -> Self: ... + def fromhex(cls, __string: str) -> Self: ... @staticmethod def maketrans(__frm: ReadableBuffer, __to: ReadableBuffer) -> bytes: ... def __len__(self) -> int: ... @@ -791,10 +791,10 @@ class bytearray(MutableSequence[int], ByteString): def __delitem__(self, __i: SupportsIndex | slice) -> None: ... def __add__(self, __s: ReadableBuffer) -> bytearray: ... # The superclass wants us to accept Iterable[int], but that fails at runtime. - def __iadd__(self: Self, __s: ReadableBuffer) -> Self: ... # type: ignore[override] + def __iadd__(self, __s: ReadableBuffer) -> Self: ... # type: ignore[override] def __mul__(self, __n: SupportsIndex) -> bytearray: ... def __rmul__(self, __n: SupportsIndex) -> bytearray: ... - def __imul__(self: Self, __n: SupportsIndex) -> Self: ... + def __imul__(self, __n: SupportsIndex) -> Self: ... def __mod__(self, __value: Any) -> bytes: ... # Incompatible with Sequence.__contains__ def __contains__(self, __o: SupportsIndex | ReadableBuffer) -> bool: ... # type: ignore[override] @@ -833,7 +833,7 @@ class memoryview(Sequence[int]): @property def nbytes(self) -> int: ... def __init__(self, obj: ReadableBuffer) -> None: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__( self, __exc_type: type[BaseException] | None, __exc_val: BaseException | None, __exc_tb: TracebackType | None ) -> None: ... @@ -868,7 +868,7 @@ class memoryview(Sequence[int]): @final class bool(int): - def __new__(cls: type[Self], __o: object = ...) -> Self: ... + def __new__(cls, __o: object = ...) -> Self: ... # The following overloads could be represented more elegantly with a TypeVar("_B", bool, int), # however mypy has a bug regarding TypeVar constraints (https://github.com/python/mypy/issues/11880). @overload @@ -913,7 +913,7 @@ class slice: def indices(self, __len: SupportsIndex) -> tuple[int, int, int]: ... class tuple(Sequence[_T_co], Generic[_T_co]): - def __new__(cls: type[Self], __iterable: Iterable[_T_co] = ...) -> Self: ... + def __new__(cls, __iterable: Iterable[_T_co] = ...) -> Self: ... def __len__(self) -> int: ... def __contains__(self, __x: object) -> bool: ... @overload @@ -1001,10 +1001,10 @@ class list(MutableSequence[_T], Generic[_T]): def __add__(self, __x: list[_T]) -> list[_T]: ... @overload def __add__(self, __x: list[_S]) -> list[_S | _T]: ... - def __iadd__(self: Self, __x: Iterable[_T]) -> Self: ... # type: ignore[misc] + def __iadd__(self, __x: Iterable[_T]) -> Self: ... # type: ignore[misc] def __mul__(self, __n: SupportsIndex) -> list[_T]: ... def __rmul__(self, __n: SupportsIndex) -> list[_T]: ... - def __imul__(self: Self, __n: SupportsIndex) -> Self: ... + def __imul__(self, __n: SupportsIndex) -> Self: ... def __contains__(self, __o: object) -> bool: ... def __reversed__(self) -> Iterator[_T]: ... def __gt__(self, __x: list[_T]) -> bool: ... @@ -1033,7 +1033,7 @@ class dict(MutableMapping[_KT, _VT], Generic[_KT, _VT]): # Cannot be Iterable[Sequence[_T]] or otherwise dict(["foo", "bar", "baz"]) is not an error @overload def __init__(self: dict[str, str], __iterable: Iterable[list[str]]) -> None: ... - def __new__(cls: type[Self], *args: Any, **kwargs: Any) -> Self: ... + def __new__(cls, *args: Any, **kwargs: Any) -> Self: ... def copy(self) -> dict[_KT, _VT]: ... def keys(self) -> dict_keys[_KT, _VT]: ... def values(self) -> dict_values[_KT, _VT]: ... @@ -1070,9 +1070,9 @@ class dict(MutableMapping[_KT, _VT], Generic[_KT, _VT]): def __ror__(self, __value: Mapping[_T1, _T2]) -> dict[_KT | _T1, _VT | _T2]: ... # dict.__ior__ should be kept roughly in line with MutableMapping.update() @overload # type: ignore[misc] - def __ior__(self: Self, __value: SupportsKeysAndGetItem[_KT, _VT]) -> Self: ... + def __ior__(self, __value: SupportsKeysAndGetItem[_KT, _VT]) -> Self: ... @overload - def __ior__(self: Self, __value: Iterable[tuple[_KT, _VT]]) -> Self: ... + def __ior__(self, __value: Iterable[tuple[_KT, _VT]]) -> Self: ... class set(MutableSet[_T], Generic[_T]): @overload @@ -1098,13 +1098,13 @@ class set(MutableSet[_T], Generic[_T]): def __contains__(self, __o: object) -> bool: ... def __iter__(self) -> Iterator[_T]: ... def __and__(self, __s: AbstractSet[object]) -> set[_T]: ... - def __iand__(self: Self, __s: AbstractSet[object]) -> Self: ... + def __iand__(self, __s: AbstractSet[object]) -> Self: ... def __or__(self, __s: AbstractSet[_S]) -> set[_T | _S]: ... - def __ior__(self: Self, __s: AbstractSet[_T]) -> Self: ... # type: ignore[override,misc] + def __ior__(self, __s: AbstractSet[_T]) -> Self: ... # type: ignore[override,misc] def __sub__(self, __s: AbstractSet[_T | None]) -> set[_T]: ... - def __isub__(self: Self, __s: AbstractSet[object]) -> Self: ... + def __isub__(self, __s: AbstractSet[object]) -> Self: ... def __xor__(self, __s: AbstractSet[_S]) -> set[_T | _S]: ... - def __ixor__(self: Self, __s: AbstractSet[_T]) -> Self: ... # type: ignore[override,misc] + def __ixor__(self, __s: AbstractSet[_T]) -> Self: ... # type: ignore[override,misc] def __le__(self, __s: AbstractSet[object]) -> bool: ... def __lt__(self, __s: AbstractSet[object]) -> bool: ... def __ge__(self, __s: AbstractSet[object]) -> bool: ... @@ -1115,9 +1115,9 @@ class set(MutableSet[_T], Generic[_T]): class frozenset(AbstractSet[_T_co], Generic[_T_co]): @overload - def __new__(cls: type[Self]) -> Self: ... + def __new__(cls) -> Self: ... @overload - def __new__(cls: type[Self], __iterable: Iterable[_T_co]) -> Self: ... + def __new__(cls, __iterable: Iterable[_T_co]) -> Self: ... def copy(self) -> frozenset[_T_co]: ... def difference(self, *s: Iterable[object]) -> frozenset[_T_co]: ... def intersection(self, *s: Iterable[object]) -> frozenset[_T_co]: ... @@ -1142,7 +1142,7 @@ class frozenset(AbstractSet[_T_co], Generic[_T_co]): class enumerate(Iterator[tuple[int, _T]], Generic[_T]): def __init__(self, iterable: Iterable[_T], start: int = ...) -> None: ... - def __iter__(self: Self) -> Self: ... + def __iter__(self) -> Self: ... def __next__(self) -> tuple[int, _T]: ... if sys.version_info >= (3, 9): def __class_getitem__(cls, __item: Any) -> GenericAlias: ... @@ -1354,7 +1354,7 @@ class filter(Iterator[_T], Generic[_T]): def __init__(self, __function: Callable[[_S], TypeGuard[_T]], __iterable: Iterable[_S]) -> None: ... @overload def __init__(self, __function: Callable[[_T], Any], __iterable: Iterable[_T]) -> None: ... - def __iter__(self: Self) -> Self: ... + def __iter__(self) -> Self: ... def __next__(self) -> _T: ... def format(__value: object, __format_spec: str = "") -> str: ... @@ -1445,7 +1445,7 @@ class map(Iterator[_S], Generic[_S]): __iter6: Iterable[Any], *iterables: Iterable[Any], ) -> None: ... - def __iter__(self: Self) -> Self: ... + def __iter__(self) -> Self: ... def __next__(self) -> _S: ... @overload @@ -1682,7 +1682,7 @@ class reversed(Iterator[_T], Generic[_T]): def __init__(self, __sequence: Reversible[_T]) -> None: ... @overload def __init__(self, __sequence: SupportsLenAndGetItem[_T]) -> None: ... - def __iter__(self: Self) -> Self: ... + def __iter__(self) -> Self: ... def __next__(self) -> _T: ... def __length_hint__(self) -> int: ... @@ -1826,7 +1826,7 @@ class zip(Iterator[_T_co], Generic[_T_co]): *iterables: Iterable[Any], ) -> zip[tuple[Any, ...]]: ... - def __iter__(self: Self) -> Self: ... + def __iter__(self) -> Self: ... def __next__(self) -> _T_co: ... # Signature of `builtins.__import__` should be kept identical to `importlib.__import__` @@ -1856,7 +1856,7 @@ class BaseException: __traceback__: TracebackType | None def __init__(self, *args: object) -> None: ... def __setstate__(self, __state: dict[str, Any] | None) -> None: ... - def with_traceback(self: Self, __tb: TracebackType | None) -> Self: ... + def with_traceback(self, __tb: TracebackType | None) -> Self: ... if sys.version_info >= (3, 11): # only present after add_note() is called __notes__: list[str] @@ -2009,7 +2009,7 @@ if sys.version_info >= (3, 11): # See `check_exception_group.py` for use-cases and comments. class BaseExceptionGroup(BaseException, Generic[_BaseExceptionT_co]): - def __new__(cls: type[Self], __message: str, __exceptions: Sequence[_BaseExceptionT_co]) -> Self: ... + def __new__(cls, __message: str, __exceptions: Sequence[_BaseExceptionT_co]) -> Self: ... def __init__(self, __message: str, __exceptions: Sequence[_BaseExceptionT_co]) -> None: ... @property def message(self) -> str: ... @@ -2025,7 +2025,7 @@ if sys.version_info >= (3, 11): ) -> BaseExceptionGroup[_BaseExceptionT] | None: ... @overload def subgroup( - self: Self, __condition: Callable[[_BaseExceptionT_co | Self], bool] + self, __condition: Callable[[_BaseExceptionT_co | Self], bool] ) -> BaseExceptionGroup[_BaseExceptionT_co] | None: ... @overload def split( @@ -2037,7 +2037,7 @@ if sys.version_info >= (3, 11): ) -> tuple[BaseExceptionGroup[_BaseExceptionT] | None, BaseExceptionGroup[_BaseExceptionT_co] | None]: ... @overload def split( - self: Self, __condition: Callable[[_BaseExceptionT_co | Self], bool] + self, __condition: Callable[[_BaseExceptionT_co | Self], bool] ) -> tuple[BaseExceptionGroup[_BaseExceptionT_co] | None, BaseExceptionGroup[_BaseExceptionT_co] | None]: ... # In reality it is `NonEmptySequence`: @overload @@ -2047,7 +2047,7 @@ if sys.version_info >= (3, 11): def __class_getitem__(cls, __item: Any) -> GenericAlias: ... class ExceptionGroup(BaseExceptionGroup[_ExceptionT_co], Exception): - def __new__(cls: type[Self], __message: str, __exceptions: Sequence[_ExceptionT_co]) -> Self: ... + def __new__(cls, __message: str, __exceptions: Sequence[_ExceptionT_co]) -> Self: ... def __init__(self, __message: str, __exceptions: Sequence[_ExceptionT_co]) -> None: ... @property def exceptions(self) -> tuple[_ExceptionT_co | ExceptionGroup[_ExceptionT_co], ...]: ... @@ -2057,14 +2057,12 @@ if sys.version_info >= (3, 11): self, __condition: type[_ExceptionT] | tuple[type[_ExceptionT], ...] ) -> ExceptionGroup[_ExceptionT] | None: ... @overload - def subgroup( - self: Self, __condition: Callable[[_ExceptionT_co | Self], bool] - ) -> ExceptionGroup[_ExceptionT_co] | None: ... + def subgroup(self, __condition: Callable[[_ExceptionT_co | Self], bool]) -> ExceptionGroup[_ExceptionT_co] | None: ... @overload # type: ignore[override] def split( self, __condition: type[_ExceptionT] | tuple[type[_ExceptionT], ...] ) -> tuple[ExceptionGroup[_ExceptionT] | None, ExceptionGroup[_ExceptionT_co] | None]: ... @overload def split( - self: Self, __condition: Callable[[_ExceptionT_co | Self], bool] + self, __condition: Callable[[_ExceptionT_co | Self], bool] ) -> tuple[ExceptionGroup[_ExceptionT_co] | None, ExceptionGroup[_ExceptionT_co] | None]: ... diff --git a/stdlib/bz2.pyi b/stdlib/bz2.pyi index 8a7151d9e456..9ad80ee6f731 100644 --- a/stdlib/bz2.pyi +++ b/stdlib/bz2.pyi @@ -1,10 +1,10 @@ import _compression import sys from _compression import BaseStream -from _typeshed import ReadableBuffer, Self, StrOrBytesPath, WriteableBuffer +from _typeshed import ReadableBuffer, StrOrBytesPath, WriteableBuffer from collections.abc import Iterable from typing import IO, Any, Protocol, TextIO, overload -from typing_extensions import Literal, SupportsIndex, TypeAlias, final +from typing_extensions import Literal, Self, SupportsIndex, TypeAlias, final __all__ = ["BZ2File", "BZ2Compressor", "BZ2Decompressor", "open", "compress", "decompress"] @@ -92,7 +92,7 @@ def open( ) -> BZ2File | TextIO: ... class BZ2File(BaseStream, IO[bytes]): - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... if sys.version_info >= (3, 9): @overload def __init__(self, filename: _WritableFileobj, mode: _WriteBinaryMode, *, compresslevel: int = 9) -> None: ... diff --git a/stdlib/cProfile.pyi b/stdlib/cProfile.pyi index 77608b268f6f..8945b21427ab 100644 --- a/stdlib/cProfile.pyi +++ b/stdlib/cProfile.pyi @@ -1,9 +1,9 @@ import sys -from _typeshed import Self, StrOrBytesPath, Unused +from _typeshed import StrOrBytesPath, Unused from collections.abc import Callable from types import CodeType from typing import Any, TypeVar -from typing_extensions import ParamSpec, TypeAlias +from typing_extensions import ParamSpec, Self, TypeAlias __all__ = ["run", "runctx", "Profile"] @@ -27,11 +27,11 @@ class Profile: def dump_stats(self, file: StrOrBytesPath) -> None: ... def create_stats(self) -> None: ... def snapshot_stats(self) -> None: ... - def run(self: Self, cmd: str) -> Self: ... - def runctx(self: Self, cmd: str, globals: dict[str, Any], locals: dict[str, Any]) -> Self: ... + def run(self, cmd: str) -> Self: ... + def runctx(self, cmd: str, globals: dict[str, Any], locals: dict[str, Any]) -> Self: ... def runcall(self, __func: Callable[_P, _T], *args: _P.args, **kw: _P.kwargs) -> _T: ... if sys.version_info >= (3, 8): - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__(self, *exc_info: Unused) -> None: ... def label(code: str | CodeType) -> _Label: ... # undocumented diff --git a/stdlib/cgi.pyi b/stdlib/cgi.pyi index 6f5637e3cce1..a2acfa92d463 100644 --- a/stdlib/cgi.pyi +++ b/stdlib/cgi.pyi @@ -1,10 +1,11 @@ import sys -from _typeshed import Self, SupportsGetItem, SupportsItemAccess, Unused +from _typeshed import SupportsGetItem, SupportsItemAccess, Unused from builtins import list as _list, type as _type from collections.abc import Iterable, Iterator, Mapping from email.message import Message from types import TracebackType from typing import IO, Any, Protocol +from typing_extensions import Self __all__ = [ "MiniFieldStorage", @@ -105,7 +106,7 @@ class FieldStorage: max_num_fields: int | None = None, separator: str = "&", ) -> None: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__(self, *args: Unused) -> None: ... def __iter__(self) -> Iterator[str]: ... def __getitem__(self, key: str) -> Any: ... diff --git a/stdlib/codecs.pyi b/stdlib/codecs.pyi index 33d0e6709923..5a22853b6aee 100644 --- a/stdlib/codecs.pyi +++ b/stdlib/codecs.pyi @@ -1,11 +1,11 @@ import sys import types from _codecs import * -from _typeshed import ReadableBuffer, Self +from _typeshed import ReadableBuffer from abc import abstractmethod from collections.abc import Callable, Generator, Iterable from typing import Any, BinaryIO, Protocol, TextIO -from typing_extensions import Literal +from typing_extensions import Literal, Self __all__ = [ "register", @@ -110,7 +110,7 @@ class CodecInfo(tuple[_Encoder, _Decoder, _StreamReader, _StreamWriter]): def incrementaldecoder(self) -> _IncrementalDecoder: ... name: str def __new__( - cls: type[Self], + cls, encode: _Encoder, decode: _Decoder, streamreader: _StreamReader | None = None, @@ -210,7 +210,7 @@ class StreamWriter(Codec): def write(self, object: str) -> None: ... def writelines(self, list: Iterable[str]) -> None: ... def reset(self) -> None: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__(self, type: type[BaseException] | None, value: BaseException | None, tb: types.TracebackType | None) -> None: ... def __getattr__(self, name: str, getattr: Callable[[str], Any] = ...) -> Any: ... @@ -222,9 +222,9 @@ class StreamReader(Codec): def readline(self, size: int | None = None, keepends: bool = True) -> str: ... def readlines(self, sizehint: int | None = None, keepends: bool = True) -> list[str]: ... def reset(self) -> None: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__(self, type: type[BaseException] | None, value: BaseException | None, tb: types.TracebackType | None) -> None: ... - def __iter__(self: Self) -> Self: ... + def __iter__(self) -> Self: ... def __next__(self) -> str: ... def __getattr__(self, name: str, getattr: Callable[[str], Any] = ...) -> Any: ... @@ -237,12 +237,12 @@ class StreamReaderWriter(TextIO): def readline(self, size: int | None = None) -> str: ... def readlines(self, sizehint: int | None = None) -> list[str]: ... def __next__(self) -> str: ... - def __iter__(self: Self) -> Self: ... + def __iter__(self) -> Self: ... def write(self, data: str) -> None: ... # type: ignore[override] def writelines(self, list: Iterable[str]) -> None: ... def reset(self) -> None: ... def seek(self, offset: int, whence: int = 0) -> None: ... # type: ignore[override] - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__(self, type: type[BaseException] | None, value: BaseException | None, tb: types.TracebackType | None) -> None: ... def __getattr__(self, name: str) -> Any: ... # These methods don't actually exist directly, but they are needed to satisfy the TextIO @@ -271,12 +271,12 @@ class StreamRecoder(BinaryIO): def readline(self, size: int | None = None) -> bytes: ... def readlines(self, sizehint: int | None = None) -> list[bytes]: ... def __next__(self) -> bytes: ... - def __iter__(self: Self) -> Self: ... + def __iter__(self) -> Self: ... def write(self, data: bytes) -> None: ... # type: ignore[override] def writelines(self, list: Iterable[bytes]) -> None: ... def reset(self) -> None: ... def __getattr__(self, name: str) -> Any: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__(self, type: type[BaseException] | None, value: BaseException | None, tb: types.TracebackType | None) -> None: ... def seek(self, offset: int, whence: int = 0) -> None: ... # type: ignore[override] # These methods don't actually exist directly, but they are needed to satisfy the BinaryIO diff --git a/stdlib/collections/__init__.pyi b/stdlib/collections/__init__.pyi index e5288e00e05c..893a289d3cb1 100644 --- a/stdlib/collections/__init__.pyi +++ b/stdlib/collections/__init__.pyi @@ -1,8 +1,8 @@ import sys from _collections_abc import dict_items, dict_keys, dict_values -from _typeshed import Self, SupportsKeysAndGetItem, SupportsRichComparison, SupportsRichComparisonT +from _typeshed import SupportsKeysAndGetItem, SupportsRichComparison, SupportsRichComparisonT from typing import Any, Generic, NoReturn, TypeVar, overload -from typing_extensions import SupportsIndex, final +from typing_extensions import Self, SupportsIndex, final if sys.version_info >= (3, 9): from types import GenericAlias @@ -68,8 +68,8 @@ class UserDict(MutableMapping[_KT, _VT], Generic[_KT, _VT]): def __delitem__(self, key: _KT) -> None: ... def __iter__(self) -> Iterator[_KT]: ... def __contains__(self, key: object) -> bool: ... - def copy(self: Self) -> Self: ... - def __copy__(self: Self) -> Self: ... + def copy(self) -> Self: ... + def __copy__(self) -> Self: ... # `UserDict.fromkeys` has the same semantics as `dict.fromkeys`, so should be kept in line with `dict.fromkeys`. # TODO: Much like `dict.fromkeys`, the true signature of `UserDict.fromkeys` is inexpressible in the current type system. @@ -85,9 +85,9 @@ class UserDict(MutableMapping[_KT, _VT], Generic[_KT, _VT]): def __ror__(self, other: UserDict[_T1, _T2] | dict[_T1, _T2]) -> UserDict[_KT | _T1, _VT | _T2]: ... # type: ignore[misc] # UserDict.__ior__ should be kept roughly in line with MutableMapping.update() @overload # type: ignore[misc] - def __ior__(self: Self, other: SupportsKeysAndGetItem[_KT, _VT]) -> Self: ... + def __ior__(self, other: SupportsKeysAndGetItem[_KT, _VT]) -> Self: ... @overload - def __ior__(self: Self, other: Iterable[tuple[_KT, _VT]]) -> Self: ... + def __ior__(self, other: Iterable[tuple[_KT, _VT]]) -> Self: ... class UserList(MutableSequence[_T]): data: list[_T] @@ -105,24 +105,24 @@ class UserList(MutableSequence[_T]): @overload def __getitem__(self, i: SupportsIndex) -> _T: ... @overload - def __getitem__(self: Self, i: slice) -> Self: ... + def __getitem__(self, i: slice) -> Self: ... @overload def __setitem__(self, i: SupportsIndex, item: _T) -> None: ... @overload def __setitem__(self, i: slice, item: Iterable[_T]) -> None: ... def __delitem__(self, i: SupportsIndex | slice) -> None: ... - def __add__(self: Self, other: Iterable[_T]) -> Self: ... - def __radd__(self: Self, other: Iterable[_T]) -> Self: ... - def __iadd__(self: Self, other: Iterable[_T]) -> Self: ... - def __mul__(self: Self, n: int) -> Self: ... - def __rmul__(self: Self, n: int) -> Self: ... - def __imul__(self: Self, n: int) -> Self: ... + def __add__(self, other: Iterable[_T]) -> Self: ... + def __radd__(self, other: Iterable[_T]) -> Self: ... + def __iadd__(self, other: Iterable[_T]) -> Self: ... + def __mul__(self, n: int) -> Self: ... + def __rmul__(self, n: int) -> Self: ... + def __imul__(self, n: int) -> Self: ... def append(self, item: _T) -> None: ... def insert(self, i: int, item: _T) -> None: ... def pop(self, i: int = -1) -> _T: ... def remove(self, item: _T) -> None: ... - def copy(self: Self) -> Self: ... - def __copy__(self: Self) -> Self: ... + def copy(self) -> Self: ... + def __copy__(self) -> Self: ... def count(self, item: _T) -> int: ... # All arguments are passed to `list.index` at runtime, so the signature should be kept in line with `list.index`. def index(self, item: _T, __start: SupportsIndex = 0, __stop: SupportsIndex = sys.maxsize) -> int: ... @@ -147,30 +147,30 @@ class UserString(Sequence[UserString]): def __eq__(self, string: object) -> bool: ... def __contains__(self, char: object) -> bool: ... def __len__(self) -> int: ... - def __getitem__(self: Self, index: SupportsIndex | slice) -> Self: ... - def __iter__(self: Self) -> Iterator[Self]: ... - def __reversed__(self: Self) -> Iterator[Self]: ... - def __add__(self: Self, other: object) -> Self: ... - def __radd__(self: Self, other: object) -> Self: ... - def __mul__(self: Self, n: int) -> Self: ... - def __rmul__(self: Self, n: int) -> Self: ... - def __mod__(self: Self, args: Any) -> Self: ... + def __getitem__(self, index: SupportsIndex | slice) -> Self: ... + def __iter__(self) -> Iterator[Self]: ... + def __reversed__(self) -> Iterator[Self]: ... + def __add__(self, other: object) -> Self: ... + def __radd__(self, other: object) -> Self: ... + def __mul__(self, n: int) -> Self: ... + def __rmul__(self, n: int) -> Self: ... + def __mod__(self, args: Any) -> Self: ... if sys.version_info >= (3, 8): - def __rmod__(self: Self, template: object) -> Self: ... + def __rmod__(self, template: object) -> Self: ... else: - def __rmod__(self: Self, format: Any) -> Self: ... + def __rmod__(self, format: Any) -> Self: ... - def capitalize(self: Self) -> Self: ... - def casefold(self: Self) -> Self: ... - def center(self: Self, width: int, *args: Any) -> Self: ... + def capitalize(self) -> Self: ... + def casefold(self) -> Self: ... + def center(self, width: int, *args: Any) -> Self: ... def count(self, sub: str | UserString, start: int = 0, end: int = sys.maxsize) -> int: ... if sys.version_info >= (3, 8): def encode(self: UserString, encoding: str | None = "utf-8", errors: str | None = "strict") -> bytes: ... else: - def encode(self: Self, encoding: str | None = None, errors: str | None = None) -> Self: ... + def encode(self, encoding: str | None = None, errors: str | None = None) -> Self: ... def endswith(self, suffix: str | tuple[str, ...], start: int | None = 0, end: int | None = sys.maxsize) -> bool: ... - def expandtabs(self: Self, tabsize: int = 8) -> Self: ... + def expandtabs(self, tabsize: int = 8) -> Self: ... def find(self, sub: str | UserString, start: int = 0, end: int = sys.maxsize) -> int: ... def format(self, *args: Any, **kwds: Any) -> str: ... def format_map(self, mapping: Mapping[str, Any]) -> str: ... @@ -188,31 +188,31 @@ class UserString(Sequence[UserString]): def isupper(self) -> bool: ... def isascii(self) -> bool: ... def join(self, seq: Iterable[str]) -> str: ... - def ljust(self: Self, width: int, *args: Any) -> Self: ... - def lower(self: Self) -> Self: ... - def lstrip(self: Self, chars: str | None = None) -> Self: ... + def ljust(self, width: int, *args: Any) -> Self: ... + def lower(self) -> Self: ... + def lstrip(self, chars: str | None = None) -> Self: ... maketrans = str.maketrans def partition(self, sep: str) -> tuple[str, str, str]: ... if sys.version_info >= (3, 9): - def removeprefix(self: Self, __prefix: str | UserString) -> Self: ... - def removesuffix(self: Self, __suffix: str | UserString) -> Self: ... + def removeprefix(self, __prefix: str | UserString) -> Self: ... + def removesuffix(self, __suffix: str | UserString) -> Self: ... - def replace(self: Self, old: str | UserString, new: str | UserString, maxsplit: int = -1) -> Self: ... + def replace(self, old: str | UserString, new: str | UserString, maxsplit: int = -1) -> Self: ... def rfind(self, sub: str | UserString, start: int = 0, end: int = sys.maxsize) -> int: ... def rindex(self, sub: str | UserString, start: int = 0, end: int = sys.maxsize) -> int: ... - def rjust(self: Self, width: int, *args: Any) -> Self: ... + def rjust(self, width: int, *args: Any) -> Self: ... def rpartition(self, sep: str) -> tuple[str, str, str]: ... - def rstrip(self: Self, chars: str | None = None) -> Self: ... + def rstrip(self, chars: str | None = None) -> Self: ... def split(self, sep: str | None = None, maxsplit: int = -1) -> list[str]: ... def rsplit(self, sep: str | None = None, maxsplit: int = -1) -> list[str]: ... def splitlines(self, keepends: bool = False) -> list[str]: ... def startswith(self, prefix: str | tuple[str, ...], start: int | None = 0, end: int | None = sys.maxsize) -> bool: ... - def strip(self: Self, chars: str | None = None) -> Self: ... - def swapcase(self: Self) -> Self: ... - def title(self: Self) -> Self: ... - def translate(self: Self, *args: Any) -> Self: ... - def upper(self: Self) -> Self: ... - def zfill(self: Self, width: int) -> Self: ... + def strip(self, chars: str | None = None) -> Self: ... + def swapcase(self) -> Self: ... + def title(self) -> Self: ... + def translate(self, *args: Any) -> Self: ... + def upper(self) -> Self: ... + def zfill(self, width: int) -> Self: ... class deque(MutableSequence[_T], Generic[_T]): @property @@ -223,7 +223,7 @@ class deque(MutableSequence[_T], Generic[_T]): def __init__(self, iterable: Iterable[_T], maxlen: int | None = None) -> None: ... def append(self, __x: _T) -> None: ... def appendleft(self, __x: _T) -> None: ... - def copy(self: Self) -> Self: ... + def copy(self) -> Self: ... def count(self, __x: _T) -> int: ... def extend(self, __iterable: Iterable[_T]) -> None: ... def extendleft(self, __iterable: Iterable[_T]) -> None: ... @@ -233,18 +233,18 @@ class deque(MutableSequence[_T], Generic[_T]): def popleft(self) -> _T: ... def remove(self, __value: _T) -> None: ... def rotate(self, __n: int = 1) -> None: ... - def __copy__(self: Self) -> Self: ... + def __copy__(self) -> Self: ... def __len__(self) -> int: ... # These methods of deque don't take slices, unlike MutableSequence, hence the type: ignores def __getitem__(self, __index: SupportsIndex) -> _T: ... # type: ignore[override] def __setitem__(self, __i: SupportsIndex, __x: _T) -> None: ... # type: ignore[override] def __delitem__(self, __i: SupportsIndex) -> None: ... # type: ignore[override] def __contains__(self, __o: object) -> bool: ... - def __reduce__(self: Self) -> tuple[type[Self], tuple[()], None, Iterator[_T]]: ... - def __iadd__(self: Self, __iterable: Iterable[_T]) -> Self: ... - def __add__(self: Self, __other: Self) -> Self: ... - def __mul__(self: Self, __other: int) -> Self: ... - def __imul__(self: Self, __other: int) -> Self: ... + def __reduce__(self) -> tuple[type[Self], tuple[()], None, Iterator[_T]]: ... + def __iadd__(self, __iterable: Iterable[_T]) -> Self: ... + def __add__(self, __other: Self) -> Self: ... + def __mul__(self, __other: int) -> Self: ... + def __imul__(self, __other: int) -> Self: ... def __lt__(self, __other: deque[_T]) -> bool: ... def __le__(self, __other: deque[_T]) -> bool: ... def __gt__(self, __other: deque[_T]) -> bool: ... @@ -261,7 +261,7 @@ class Counter(dict[_T, int], Generic[_T]): def __init__(self, __mapping: SupportsKeysAndGetItem[_T, int]) -> None: ... @overload def __init__(self, __iterable: Iterable[_T]) -> None: ... - def copy(self: Self) -> Self: ... + def copy(self) -> Self: ... def elements(self) -> Iterator[_T]: ... def most_common(self, n: int | None = None) -> list[tuple[_T, int]]: ... @classmethod @@ -297,10 +297,10 @@ class Counter(dict[_T, int], Generic[_T]): def __pos__(self) -> Counter[_T]: ... def __neg__(self) -> Counter[_T]: ... # several type: ignores because __iadd__ is supposedly incompatible with __add__, etc. - def __iadd__(self: Self, other: Counter[_T]) -> Self: ... # type: ignore[misc] - def __isub__(self: Self, other: Counter[_T]) -> Self: ... - def __iand__(self: Self, other: Counter[_T]) -> Self: ... - def __ior__(self: Self, other: Counter[_T]) -> Self: ... # type: ignore[override,misc] + def __iadd__(self, other: Counter[_T]) -> Self: ... # type: ignore[misc] + def __isub__(self, other: Counter[_T]) -> Self: ... + def __iand__(self, other: Counter[_T]) -> Self: ... + def __ior__(self, other: Counter[_T]) -> Self: ... # type: ignore[override,misc] if sys.version_info >= (3, 10): def total(self) -> int: ... def __le__(self, other: Counter[Any]) -> bool: ... @@ -338,7 +338,7 @@ class _odict_values(dict_values[_KT_co, _VT_co], Reversible[_VT_co], Generic[_KT class OrderedDict(dict[_KT, _VT], Reversible[_KT], Generic[_KT, _VT]): def popitem(self, last: bool = True) -> tuple[_KT, _VT]: ... def move_to_end(self, key: _KT, last: bool = True) -> None: ... - def copy(self: Self) -> Self: ... + def copy(self) -> Self: ... def __reversed__(self) -> Iterator[_KT]: ... def keys(self) -> _odict_keys[_KT, _VT]: ... def items(self) -> _odict_items[_KT, _VT]: ... @@ -387,15 +387,15 @@ class defaultdict(dict[_KT, _VT], Generic[_KT, _VT]): **kwargs: _VT, ) -> None: ... def __missing__(self, __key: _KT) -> _VT: ... - def __copy__(self: Self) -> Self: ... - def copy(self: Self) -> Self: ... + def __copy__(self) -> Self: ... + def copy(self) -> Self: ... class ChainMap(MutableMapping[_KT, _VT], Generic[_KT, _VT]): maps: list[MutableMapping[_KT, _VT]] def __init__(self, *maps: MutableMapping[_KT, _VT]) -> None: ... - def new_child(self: Self, m: MutableMapping[_KT, _VT] | None = None) -> Self: ... + def new_child(self, m: MutableMapping[_KT, _VT] | None = None) -> Self: ... @property - def parents(self: Self) -> Self: ... + def parents(self) -> Self: ... def __setitem__(self, key: _KT, value: _VT) -> None: ... def __delitem__(self, key: _KT) -> None: ... def __getitem__(self, key: _KT) -> _VT: ... @@ -413,7 +413,7 @@ class ChainMap(MutableMapping[_KT, _VT], Generic[_KT, _VT]): def pop(self, key: _KT) -> _VT: ... @overload def pop(self, key: _KT, default: _VT | _T) -> _VT | _T: ... - def copy(self: Self) -> Self: ... + def copy(self) -> Self: ... __copy__ = copy # All arguments to `fromkeys` are passed to `dict.fromkeys` at runtime, so the signature should be kept in line with `dict.fromkeys`. @classmethod @@ -427,6 +427,6 @@ class ChainMap(MutableMapping[_KT, _VT], Generic[_KT, _VT]): def __ror__(self, other: Mapping[_T1, _T2]) -> ChainMap[_KT | _T1, _VT | _T2]: ... # ChainMap.__ior__ should be kept roughly in line with MutableMapping.update() @overload # type: ignore[misc] - def __ior__(self: Self, other: SupportsKeysAndGetItem[_KT, _VT]) -> Self: ... + def __ior__(self, other: SupportsKeysAndGetItem[_KT, _VT]) -> Self: ... @overload - def __ior__(self: Self, other: Iterable[tuple[_KT, _VT]]) -> Self: ... + def __ior__(self, other: Iterable[tuple[_KT, _VT]]) -> Self: ... diff --git a/stdlib/concurrent/futures/_base.pyi b/stdlib/concurrent/futures/_base.pyi index 64084a884433..e792cf1a83c0 100644 --- a/stdlib/concurrent/futures/_base.pyi +++ b/stdlib/concurrent/futures/_base.pyi @@ -1,11 +1,11 @@ import sys import threading -from _typeshed import Self, Unused +from _typeshed import Unused from collections.abc import Callable, Iterable, Iterator, Sequence from logging import Logger from types import TracebackType from typing import Any, Generic, TypeVar, overload -from typing_extensions import Literal, ParamSpec, SupportsIndex +from typing_extensions import Literal, ParamSpec, Self, SupportsIndex if sys.version_info >= (3, 9): from types import GenericAlias @@ -62,7 +62,7 @@ class Executor: else: def shutdown(self, wait: bool = True) -> None: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__( self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None ) -> bool | None: ... diff --git a/stdlib/contextlib.pyi b/stdlib/contextlib.pyi index 522285abbc72..feb43aabb039 100644 --- a/stdlib/contextlib.pyi +++ b/stdlib/contextlib.pyi @@ -1,11 +1,11 @@ import abc import sys -from _typeshed import FileDescriptorOrPath, Self, Unused +from _typeshed import FileDescriptorOrPath, Unused from abc import abstractmethod from collections.abc import AsyncGenerator, AsyncIterator, Awaitable, Callable, Generator, Iterator from types import TracebackType from typing import IO, Any, Generic, Protocol, TypeVar, overload, runtime_checkable -from typing_extensions import ParamSpec, TypeAlias +from typing_extensions import ParamSpec, Self, TypeAlias __all__ = [ "contextmanager", @@ -140,9 +140,9 @@ class ExitStack(metaclass=abc.ABCMeta): def enter_context(self, cm: AbstractContextManager[_T]) -> _T: ... def push(self, exit: _CM_EF) -> _CM_EF: ... def callback(self, __callback: Callable[_P, _T], *args: _P.args, **kwds: _P.kwargs) -> Callable[_P, _T]: ... - def pop_all(self: Self) -> Self: ... + def pop_all(self) -> Self: ... def close(self) -> None: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__( self, __exc_type: type[BaseException] | None, __exc_value: BaseException | None, __traceback: TracebackType | None ) -> bool: ... @@ -163,9 +163,9 @@ class AsyncExitStack(metaclass=abc.ABCMeta): def push_async_callback( self, __callback: Callable[_P, Awaitable[_T]], *args: _P.args, **kwds: _P.kwargs ) -> Callable[_P, Awaitable[_T]]: ... - def pop_all(self: Self) -> Self: ... + def pop_all(self) -> Self: ... async def aclose(self) -> None: ... - async def __aenter__(self: Self) -> Self: ... + async def __aenter__(self) -> Self: ... async def __aexit__( self, __exc_type: type[BaseException] | None, __exc_value: BaseException | None, __traceback: TracebackType | None ) -> bool: ... diff --git a/stdlib/csv.pyi b/stdlib/csv.pyi index 13b483b219d5..234b189fb3db 100644 --- a/stdlib/csv.pyi +++ b/stdlib/csv.pyi @@ -21,10 +21,10 @@ from _csv import ( unregister_dialect as unregister_dialect, writer as writer, ) -from _typeshed import Self, SupportsWrite +from _typeshed import SupportsWrite from collections.abc import Collection, Iterable, Iterator, Mapping, Sequence from typing import Any, Generic, TypeVar, overload -from typing_extensions import Literal +from typing_extensions import Literal, Self if sys.version_info >= (3, 8): from builtins import dict as _DictReadMapping @@ -107,7 +107,7 @@ class DictReader(Generic[_T], Iterator[_DictReadMapping[_T | Any, str | Any]]): quoting: _QuotingType = ..., strict: bool = ..., ) -> None: ... - def __iter__(self: Self) -> Self: ... + def __iter__(self) -> Self: ... def __next__(self) -> _DictReadMapping[_T | Any, str | Any]: ... if sys.version_info >= (3, 12): def __class_getitem__(cls, item: Any) -> GenericAlias: ... diff --git a/stdlib/ctypes/__init__.pyi b/stdlib/ctypes/__init__.pyi index 87ae2513e1e7..aaaacf287903 100644 --- a/stdlib/ctypes/__init__.pyi +++ b/stdlib/ctypes/__init__.pyi @@ -1,10 +1,10 @@ import sys from _ctypes import RTLD_GLOBAL as RTLD_GLOBAL, RTLD_LOCAL as RTLD_LOCAL -from _typeshed import ReadableBuffer, Self, WriteableBuffer +from _typeshed import ReadableBuffer, WriteableBuffer from abc import abstractmethod from collections.abc import Callable, Iterable, Iterator, Mapping, Sequence from typing import Any, ClassVar, Generic, TypeVar, overload -from typing_extensions import TypeAlias +from typing_extensions import Self, TypeAlias if sys.version_info >= (3, 9): from types import GenericAlias @@ -77,15 +77,15 @@ class _CData(metaclass=_CDataMeta): _b_needsfree_: bool _objects: Mapping[Any, int] | None @classmethod - def from_buffer(cls: type[Self], source: WriteableBuffer, offset: int = ...) -> Self: ... + def from_buffer(cls, source: WriteableBuffer, offset: int = ...) -> Self: ... @classmethod - def from_buffer_copy(cls: type[Self], source: ReadableBuffer, offset: int = ...) -> Self: ... + def from_buffer_copy(cls, source: ReadableBuffer, offset: int = ...) -> Self: ... @classmethod - def from_address(cls: type[Self], address: int) -> Self: ... + def from_address(cls, address: int) -> Self: ... @classmethod - def from_param(cls: type[Self], obj: Any) -> Self | _CArgObject: ... + def from_param(cls, obj: Any) -> Self | _CArgObject: ... @classmethod - def in_dll(cls: type[Self], library: CDLL, name: str) -> Self: ... + def in_dll(cls, library: CDLL, name: str) -> Self: ... class _CanCastTo(_CData): ... class _PointerLike(_CanCastTo): ... diff --git a/stdlib/datetime.pyi b/stdlib/datetime.pyi index 377ef0067485..f8c0c2bec0ad 100644 --- a/stdlib/datetime.pyi +++ b/stdlib/datetime.pyi @@ -1,9 +1,8 @@ import sys -from _typeshed import Self from abc import abstractmethod from time import struct_time from typing import ClassVar, NamedTuple, NoReturn, TypeVar, overload -from typing_extensions import Literal, TypeAlias, final +from typing_extensions import Literal, Self, TypeAlias, final if sys.version_info >= (3, 11): __all__ = ("date", "datetime", "time", "timedelta", "timezone", "tzinfo", "MINYEAR", "MAXYEAR", "UTC") @@ -50,18 +49,18 @@ class date: min: ClassVar[date] max: ClassVar[date] resolution: ClassVar[timedelta] - def __new__(cls: type[Self], year: int, month: int, day: int) -> Self: ... + def __new__(cls, year: int, month: int, day: int) -> Self: ... @classmethod - def fromtimestamp(cls: type[Self], __timestamp: float) -> Self: ... + def fromtimestamp(cls, __timestamp: float) -> Self: ... @classmethod - def today(cls: type[Self]) -> Self: ... + def today(cls) -> Self: ... @classmethod - def fromordinal(cls: type[Self], __n: int) -> Self: ... + def fromordinal(cls, __n: int) -> Self: ... @classmethod - def fromisoformat(cls: type[Self], __date_string: str) -> Self: ... + def fromisoformat(cls, __date_string: str) -> Self: ... if sys.version_info >= (3, 8): @classmethod - def fromisocalendar(cls: type[Self], year: int, week: int, day: int) -> Self: ... + def fromisocalendar(cls, year: int, week: int, day: int) -> Self: ... @property def year(self) -> int: ... @@ -82,16 +81,16 @@ class date: def isoformat(self) -> str: ... def timetuple(self) -> struct_time: ... def toordinal(self) -> int: ... - def replace(self: Self, year: int = ..., month: int = ..., day: int = ...) -> Self: ... + def replace(self, year: int = ..., month: int = ..., day: int = ...) -> Self: ... def __le__(self, __other: date) -> bool: ... def __lt__(self, __other: date) -> bool: ... def __ge__(self, __other: date) -> bool: ... def __gt__(self, __other: date) -> bool: ... if sys.version_info >= (3, 8): - def __add__(self: Self, __other: timedelta) -> Self: ... - def __radd__(self: Self, __other: timedelta) -> Self: ... + def __add__(self, __other: timedelta) -> Self: ... + def __radd__(self, __other: timedelta) -> Self: ... @overload - def __sub__(self: Self, __other: timedelta) -> Self: ... + def __sub__(self, __other: timedelta) -> Self: ... @overload def __sub__(self, __other: datetime) -> NoReturn: ... @overload @@ -119,7 +118,7 @@ class time: max: ClassVar[time] resolution: ClassVar[timedelta] def __new__( - cls: type[Self], + cls, hour: int = ..., minute: int = ..., second: int = ..., @@ -146,7 +145,7 @@ class time: def __gt__(self, __other: time) -> bool: ... def isoformat(self, timespec: str = ...) -> str: ... @classmethod - def fromisoformat(cls: type[Self], __time_string: str) -> Self: ... + def fromisoformat(cls, __time_string: str) -> Self: ... # On <3.12, the name of the parameter in the pure-Python implementation # didn't match the name in the C implementation, # meaning it is only *safe* to pass it as a keyword argument on 3.12+ @@ -160,7 +159,7 @@ class time: def tzname(self) -> str | None: ... def dst(self) -> timedelta | None: ... def replace( - self: Self, + self, hour: int = ..., minute: int = ..., second: int = ..., @@ -178,7 +177,7 @@ class timedelta: max: ClassVar[timedelta] resolution: ClassVar[timedelta] def __new__( - cls: type[Self], + cls, days: float = ..., seconds: float = ..., microseconds: float = ..., @@ -223,7 +222,7 @@ class datetime(date): min: ClassVar[datetime] max: ClassVar[datetime] def __new__( - cls: type[Self], + cls, year: int, month: int, day: int, @@ -252,26 +251,26 @@ class datetime(date): # meaning it is only *safe* to pass it as a keyword argument on 3.12+ if sys.version_info >= (3, 12): @classmethod - def fromtimestamp(cls: type[Self], timestamp: float, tz: _TzInfo | None = ...) -> Self: ... + def fromtimestamp(cls, timestamp: float, tz: _TzInfo | None = ...) -> Self: ... else: @classmethod - def fromtimestamp(cls: type[Self], __timestamp: float, tz: _TzInfo | None = ...) -> Self: ... + def fromtimestamp(cls, __timestamp: float, tz: _TzInfo | None = ...) -> Self: ... @classmethod - def utcfromtimestamp(cls: type[Self], __t: float) -> Self: ... + def utcfromtimestamp(cls, __t: float) -> Self: ... if sys.version_info >= (3, 8): @classmethod - def now(cls: type[Self], tz: _TzInfo | None = None) -> Self: ... + def now(cls, tz: _TzInfo | None = None) -> Self: ... else: @overload @classmethod - def now(cls: type[Self], tz: None = None) -> Self: ... + def now(cls, tz: None = None) -> Self: ... @overload @classmethod def now(cls, tz: _TzInfo) -> datetime: ... @classmethod - def utcnow(cls: type[Self]) -> Self: ... + def utcnow(cls) -> Self: ... @classmethod def combine(cls, date: _Date, time: _Time, tzinfo: _TzInfo | None = ...) -> datetime: ... def timestamp(self) -> float: ... @@ -280,7 +279,7 @@ class datetime(date): def time(self) -> _Time: ... def timetz(self) -> _Time: ... def replace( - self: Self, + self, year: int = ..., month: int = ..., day: int = ..., @@ -293,7 +292,7 @@ class datetime(date): fold: int = ..., ) -> Self: ... if sys.version_info >= (3, 8): - def astimezone(self: Self, tz: _TzInfo | None = ...) -> Self: ... + def astimezone(self, tz: _TzInfo | None = ...) -> Self: ... else: def astimezone(self, tz: _TzInfo | None = ...) -> datetime: ... @@ -309,7 +308,7 @@ class datetime(date): def __gt__(self, __other: datetime) -> bool: ... # type: ignore[override] if sys.version_info >= (3, 8): @overload # type: ignore[override] - def __sub__(self: Self, __other: timedelta) -> Self: ... + def __sub__(self, __other: timedelta) -> Self: ... @overload def __sub__(self: _D, __other: _D) -> timedelta: ... else: diff --git a/stdlib/dbm/__init__.pyi b/stdlib/dbm/__init__.pyi index ab224086b7be..0068d67b6ad1 100644 --- a/stdlib/dbm/__init__.pyi +++ b/stdlib/dbm/__init__.pyi @@ -1,7 +1,6 @@ -from _typeshed import Self from collections.abc import Iterator, MutableMapping from types import TracebackType -from typing_extensions import Literal, TypeAlias +from typing_extensions import Literal, Self, TypeAlias __all__ = ["open", "whichdb", "error"] @@ -82,7 +81,7 @@ class _Database(MutableMapping[_KeyType, bytes]): def __iter__(self) -> Iterator[bytes]: ... def __len__(self) -> int: ... def __del__(self) -> None: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__( self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None ) -> None: ... diff --git a/stdlib/dbm/dumb.pyi b/stdlib/dbm/dumb.pyi index d65d163ab568..1fc68cf71f9d 100644 --- a/stdlib/dbm/dumb.pyi +++ b/stdlib/dbm/dumb.pyi @@ -1,7 +1,6 @@ -from _typeshed import Self from collections.abc import Iterator, MutableMapping from types import TracebackType -from typing_extensions import TypeAlias +from typing_extensions import Self, TypeAlias __all__ = ["error", "open"] @@ -24,7 +23,7 @@ class _Database(MutableMapping[_KeyType, bytes]): def __iter__(self) -> Iterator[bytes]: ... def __len__(self) -> int: ... def __del__(self) -> None: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__( self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None ) -> None: ... diff --git a/stdlib/dbm/gnu.pyi b/stdlib/dbm/gnu.pyi index adaf6fa8e69b..3dc66a30c370 100644 --- a/stdlib/dbm/gnu.pyi +++ b/stdlib/dbm/gnu.pyi @@ -1,8 +1,8 @@ import sys -from _typeshed import ReadOnlyBuffer, Self +from _typeshed import ReadOnlyBuffer from types import TracebackType from typing import TypeVar, overload -from typing_extensions import TypeAlias +from typing_extensions import Self, TypeAlias if sys.platform != "win32": _T = TypeVar("_T") @@ -24,7 +24,7 @@ if sys.platform != "win32": def __delitem__(self, key: _KeyType) -> None: ... def __contains__(self, key: _KeyType) -> bool: ... def __len__(self) -> int: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__( self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None ) -> None: ... diff --git a/stdlib/dbm/ndbm.pyi b/stdlib/dbm/ndbm.pyi index ac0b75dfa45b..1106fb2a8e7e 100644 --- a/stdlib/dbm/ndbm.pyi +++ b/stdlib/dbm/ndbm.pyi @@ -1,8 +1,8 @@ import sys -from _typeshed import ReadOnlyBuffer, Self +from _typeshed import ReadOnlyBuffer from types import TracebackType from typing import TypeVar, overload -from typing_extensions import TypeAlias +from typing_extensions import Self, TypeAlias if sys.platform != "win32": _T = TypeVar("_T") @@ -20,7 +20,7 @@ if sys.platform != "win32": def __delitem__(self, key: _KeyType) -> None: ... def __len__(self) -> int: ... def __del__(self) -> None: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__( self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None ) -> None: ... diff --git a/stdlib/dis.pyi b/stdlib/dis.pyi index ea837f09c806..ac0c5356f5f9 100644 --- a/stdlib/dis.pyi +++ b/stdlib/dis.pyi @@ -1,10 +1,9 @@ import sys import types -from _typeshed import Self from collections.abc import Callable, Iterator from opcode import * # `dis` re-exports it as a part of public API from typing import IO, Any, NamedTuple -from typing_extensions import TypeAlias +from typing_extensions import Self, TypeAlias __all__ = [ "code_info", @@ -82,15 +81,13 @@ class Bytecode: adaptive: bool = False, ) -> None: ... @classmethod - def from_traceback( - cls: type[Self], tb: types.TracebackType, *, show_caches: bool = False, adaptive: bool = False - ) -> Self: ... + def from_traceback(cls, tb: types.TracebackType, *, show_caches: bool = False, adaptive: bool = False) -> Self: ... else: def __init__( self, x: _HaveCodeType | str, *, first_line: int | None = None, current_offset: int | None = None ) -> None: ... @classmethod - def from_traceback(cls: type[Self], tb: types.TracebackType) -> Self: ... + def from_traceback(cls, tb: types.TracebackType) -> Self: ... def __iter__(self) -> Iterator[Instruction]: ... def info(self) -> str: ... diff --git a/stdlib/distutils/version.pyi b/stdlib/distutils/version.pyi index 4f1b64a7381d..47da65ef87aa 100644 --- a/stdlib/distutils/version.pyi +++ b/stdlib/distutils/version.pyi @@ -1,36 +1,36 @@ -from _typeshed import Self from abc import abstractmethod from re import Pattern +from typing_extensions import Self class Version: def __eq__(self, other: object) -> bool: ... - def __lt__(self: Self, other: Self | str) -> bool: ... - def __le__(self: Self, other: Self | str) -> bool: ... - def __gt__(self: Self, other: Self | str) -> bool: ... - def __ge__(self: Self, other: Self | str) -> bool: ... + def __lt__(self, other: Self | str) -> bool: ... + def __le__(self, other: Self | str) -> bool: ... + def __gt__(self, other: Self | str) -> bool: ... + def __ge__(self, other: Self | str) -> bool: ... @abstractmethod def __init__(self, vstring: str | None = None) -> None: ... @abstractmethod - def parse(self: Self, vstring: str) -> Self: ... + def parse(self, vstring: str) -> Self: ... @abstractmethod def __str__(self) -> str: ... @abstractmethod - def _cmp(self: Self, other: Self | str) -> bool: ... + def _cmp(self, other: Self | str) -> bool: ... class StrictVersion(Version): version_re: Pattern[str] version: tuple[int, int, int] prerelease: tuple[str, int] | None def __init__(self, vstring: str | None = None) -> None: ... - def parse(self: Self, vstring: str) -> Self: ... + def parse(self, vstring: str) -> Self: ... def __str__(self) -> str: ... # noqa: Y029 - def _cmp(self: Self, other: Self | str) -> bool: ... + def _cmp(self, other: Self | str) -> bool: ... class LooseVersion(Version): component_re: Pattern[str] vstring: str version: tuple[str | int, ...] def __init__(self, vstring: str | None = None) -> None: ... - def parse(self: Self, vstring: str) -> Self: ... + def parse(self, vstring: str) -> Self: ... def __str__(self) -> str: ... # noqa: Y029 - def _cmp(self: Self, other: Self | str) -> bool: ... + def _cmp(self, other: Self | str) -> bool: ... diff --git a/stdlib/email/_header_value_parser.pyi b/stdlib/email/_header_value_parser.pyi index 0e422294e77a..97008140ec5d 100644 --- a/stdlib/email/_header_value_parser.pyi +++ b/stdlib/email/_header_value_parser.pyi @@ -1,11 +1,10 @@ import sys -from _typeshed import Self from collections.abc import Iterable, Iterator from email.errors import HeaderParseError, MessageDefect from email.policy import Policy from re import Pattern from typing import Any -from typing_extensions import Final +from typing_extensions import Final, Self WSP: Final[set[str]] CFWS_LEADER: Final[set[str]] @@ -318,7 +317,7 @@ class Terminal(str): syntactic_break: bool token_type: str defects: list[MessageDefect] - def __new__(cls: type[Self], value: str, token_type: str) -> Self: ... + def __new__(cls, value: str, token_type: str) -> Self: ... def pprint(self) -> None: ... @property def all_defects(self) -> list[MessageDefect]: ... diff --git a/stdlib/email/headerregistry.pyi b/stdlib/email/headerregistry.pyi index df07e2458e81..e158e89818f7 100644 --- a/stdlib/email/headerregistry.pyi +++ b/stdlib/email/headerregistry.pyi @@ -1,6 +1,5 @@ import sys import types -from _typeshed import Self from collections.abc import Iterable, Mapping from datetime import datetime as _datetime from email._header_value_parser import ( @@ -15,7 +14,7 @@ from email._header_value_parser import ( from email.errors import MessageDefect from email.policy import Policy from typing import Any, ClassVar, Protocol -from typing_extensions import Literal +from typing_extensions import Literal, Self class BaseHeader(str): # max_count is actually more of an abstract ClassVar (not defined on the base class, but expected to be defined in subclasses) @@ -24,7 +23,7 @@ class BaseHeader(str): def name(self) -> str: ... @property def defects(self) -> tuple[MessageDefect, ...]: ... - def __new__(cls: type[Self], name: str, value: Any) -> Self: ... + def __new__(cls, name: str, value: Any) -> Self: ... def init(self, name: str, *, parse_tree: TokenList, defects: Iterable[MessageDefect]) -> None: ... def fold(self, *, policy: Policy) -> str: ... diff --git a/stdlib/email/message.pyi b/stdlib/email/message.pyi index 2777450a77ba..14e018073103 100644 --- a/stdlib/email/message.pyi +++ b/stdlib/email/message.pyi @@ -1,4 +1,3 @@ -from _typeshed import Self from collections.abc import Generator, Iterator, Sequence from email import _ParamsType, _ParamType from email.charset import Charset @@ -6,7 +5,7 @@ from email.contentmanager import ContentManager from email.errors import MessageDefect from email.policy import Policy from typing import Any, TypeVar, overload -from typing_extensions import TypeAlias +from typing_extensions import Self, TypeAlias __all__ = ["Message", "EmailMessage"] @@ -84,7 +83,7 @@ class Message: def get_charsets(self, failobj: None = None) -> list[str] | None: ... @overload def get_charsets(self, failobj: _T) -> list[str] | _T: ... - def walk(self: Self) -> Generator[Self, None, None]: ... + def walk(self) -> Generator[Self, None, None]: ... def get_content_disposition(self) -> str | None: ... def as_string(self, unixfrom: bool = False, maxheaderlen: int = 0, policy: Policy | None = None) -> str: ... def as_bytes(self, unixfrom: bool = False, policy: Policy | None = None) -> bytes: ... diff --git a/stdlib/enum.pyi b/stdlib/enum.pyi index 182076731ab2..b46fe429cacb 100644 --- a/stdlib/enum.pyi +++ b/stdlib/enum.pyi @@ -1,11 +1,12 @@ +import _typeshed import sys import types -from _typeshed import Self, SupportsKeysAndGetItem, Unused +from _typeshed import SupportsKeysAndGetItem, Unused from abc import ABCMeta from builtins import property as _builtins_property from collections.abc import Iterable, Iterator, Mapping from typing import Any, Generic, TypeVar, overload -from typing_extensions import Literal, TypeAlias +from typing_extensions import Literal, Self, TypeAlias __all__ = ["EnumMeta", "Enum", "IntEnum", "Flag", "IntFlag", "auto", "unique"] @@ -80,7 +81,7 @@ class _EnumDict(dict[str, Any]): class EnumMeta(ABCMeta): if sys.version_info >= (3, 11): def __new__( - metacls: type[Self], + metacls: type[_typeshed.Self], cls: str, bases: tuple[type, ...], classdict: _EnumDict, @@ -88,11 +89,13 @@ class EnumMeta(ABCMeta): boundary: FlagBoundary | None = None, _simple: bool = False, **kwds: Any, - ) -> Self: ... + ) -> _typeshed.Self: ... elif sys.version_info >= (3, 9): - def __new__(metacls: type[Self], cls: str, bases: tuple[type, ...], classdict: _EnumDict, **kwds: Any) -> Self: ... + def __new__( + metacls: type[_typeshed.Self], cls: str, bases: tuple[type, ...], classdict: _EnumDict, **kwds: Any + ) -> _typeshed.Self: ... else: - def __new__(metacls: type[Self], cls: str, bases: tuple[type, ...], classdict: _EnumDict) -> Self: ... + def __new__(metacls: type[_typeshed.Self], cls: str, bases: tuple[type, ...], classdict: _EnumDict) -> _typeshed.Self: ... if sys.version_info >= (3, 9): @classmethod @@ -174,7 +177,7 @@ class Enum(metaclass=EnumMeta): # However, using `Any` causes too many false-positives for those using mypy's `--disallow-any-expr` # (see #7752, #2539, mypy/#5788), # and in practice using `object` here has the same effect as using `Any`. - def __new__(cls: type[Self], value: object) -> Self: ... + def __new__(cls, value: object) -> Self: ... def __dir__(self) -> list[str]: ... def __format__(self, format_spec: str) -> str: ... def __reduce_ex__(self, proto: Unused) -> tuple[Any, ...]: ... @@ -191,7 +194,7 @@ class IntEnum(int, _IntEnumBase): _value_: int @_magic_enum_attr def value(self) -> int: ... - def __new__(cls: type[Self], value: int) -> Self: ... + def __new__(cls, value: int) -> Self: ... def unique(enumeration: _EnumerationT) -> _EnumerationT: ... @@ -202,7 +205,7 @@ class auto(IntFlag): _value_: Any @_magic_enum_attr def value(self) -> Any: ... - def __new__(cls: type[Self]) -> Self: ... + def __new__(cls) -> Self: ... class Flag(Enum): _name_: str | None # type: ignore[assignment] @@ -211,14 +214,14 @@ class Flag(Enum): def name(self) -> str | None: ... # type: ignore[override] @_magic_enum_attr def value(self) -> int: ... - def __contains__(self: Self, other: Self) -> bool: ... + def __contains__(self, other: Self) -> bool: ... def __bool__(self) -> bool: ... - def __or__(self: Self, other: Self) -> Self: ... - def __and__(self: Self, other: Self) -> Self: ... - def __xor__(self: Self, other: Self) -> Self: ... - def __invert__(self: Self) -> Self: ... + def __or__(self, other: Self) -> Self: ... + def __and__(self, other: Self) -> Self: ... + def __xor__(self, other: Self) -> Self: ... + def __invert__(self) -> Self: ... if sys.version_info >= (3, 11): - def __iter__(self: Self) -> Iterator[Self]: ... + def __iter__(self) -> Iterator[Self]: ... def __len__(self) -> int: ... __ror__ = __or__ __rand__ = __and__ @@ -226,28 +229,28 @@ class Flag(Enum): if sys.version_info >= (3, 11): # The body of the class is the same, but the base classes are different. - class IntFlag(int, ReprEnum, Flag, boundary=KEEP): - def __new__(cls: type[Self], value: int) -> Self: ... - def __or__(self: Self, other: int) -> Self: ... - def __and__(self: Self, other: int) -> Self: ... - def __xor__(self: Self, other: int) -> Self: ... + class IntFlag(int, ReprEnum, Flag, boundary=KEEP): # type: ignore[misc] # complaints about incompatible bases + def __new__(cls, value: int) -> Self: ... + def __or__(self, other: int) -> Self: ... + def __and__(self, other: int) -> Self: ... + def __xor__(self, other: int) -> Self: ... __ror__ = __or__ __rand__ = __and__ __rxor__ = __xor__ else: - class IntFlag(int, Flag): - def __new__(cls: type[Self], value: int) -> Self: ... - def __or__(self: Self, other: int) -> Self: ... - def __and__(self: Self, other: int) -> Self: ... - def __xor__(self: Self, other: int) -> Self: ... + class IntFlag(int, Flag): # type: ignore[misc] # complaints about incompatible bases + def __new__(cls, value: int) -> Self: ... + def __or__(self, other: int) -> Self: ... + def __and__(self, other: int) -> Self: ... + def __xor__(self, other: int) -> Self: ... __ror__ = __or__ __rand__ = __and__ __rxor__ = __xor__ if sys.version_info >= (3, 11): class StrEnum(str, ReprEnum): - def __new__(cls: type[Self], value: str) -> Self: ... + def __new__(cls, value: str) -> Self: ... _value_: str @_magic_enum_attr def value(self) -> str: ... diff --git a/stdlib/fileinput.pyi b/stdlib/fileinput.pyi index 17379e92ba5f..e9f3713b4eaf 100644 --- a/stdlib/fileinput.pyi +++ b/stdlib/fileinput.pyi @@ -1,9 +1,9 @@ import sys -from _typeshed import AnyStr_co, Self, StrOrBytesPath +from _typeshed import AnyStr_co, StrOrBytesPath from collections.abc import Callable, Iterable, Iterator from types import TracebackType from typing import IO, Any, AnyStr, Generic, Protocol, overload -from typing_extensions import Literal, TypeAlias +from typing_extensions import Literal, Self, TypeAlias if sys.version_info >= (3, 9): from types import GenericAlias @@ -289,11 +289,11 @@ class FileInput(Iterator[AnyStr], Generic[AnyStr]): def __del__(self) -> None: ... def close(self) -> None: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__( self, type: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None ) -> None: ... - def __iter__(self: Self) -> Self: ... + def __iter__(self) -> Self: ... def __next__(self) -> AnyStr: ... if sys.version_info < (3, 11): def __getitem__(self, i: int) -> AnyStr: ... diff --git a/stdlib/fractions.pyi b/stdlib/fractions.pyi index 95e4aad0f9ca..97cefc916d9b 100644 --- a/stdlib/fractions.pyi +++ b/stdlib/fractions.pyi @@ -1,10 +1,9 @@ import sys -from _typeshed import Self from collections.abc import Callable from decimal import Decimal from numbers import Integral, Rational, Real from typing import Any, overload -from typing_extensions import Literal, SupportsIndex, TypeAlias +from typing_extensions import Literal, Self, SupportsIndex, TypeAlias _ComparableNum: TypeAlias = int | float | Decimal | Real @@ -24,14 +23,14 @@ else: class Fraction(Rational): @overload def __new__( - cls: type[Self], numerator: int | Rational = 0, denominator: int | Rational | None = None, *, _normalize: bool = True + cls, numerator: int | Rational = 0, denominator: int | Rational | None = None, *, _normalize: bool = True ) -> Self: ... @overload - def __new__(cls: type[Self], __value: float | Decimal | str, *, _normalize: bool = True) -> Self: ... + def __new__(cls, __value: float | Decimal | str, *, _normalize: bool = True) -> Self: ... @classmethod - def from_float(cls: type[Self], f: float) -> Self: ... + def from_float(cls, f: float) -> Self: ... @classmethod - def from_decimal(cls: type[Self], dec: Decimal) -> Self: ... + def from_decimal(cls, dec: Decimal) -> Self: ... def limit_denominator(self, max_denominator: int = 1000000) -> Fraction: ... if sys.version_info >= (3, 8): def as_integer_ratio(self) -> tuple[int, int]: ... @@ -139,8 +138,8 @@ class Fraction(Rational): def __le__(a, b: _ComparableNum) -> bool: ... def __ge__(a, b: _ComparableNum) -> bool: ... def __bool__(a) -> bool: ... - def __copy__(self: Self) -> Self: ... - def __deepcopy__(self: Self, memo: Any) -> Self: ... + def __copy__(self) -> Self: ... + def __deepcopy__(self, memo: Any) -> Self: ... if sys.version_info >= (3, 11): def __int__(a, _index: Callable[[SupportsIndex], int] = ...) -> int: ... # Not actually defined within fractions.py, but provides more useful diff --git a/stdlib/ftplib.pyi b/stdlib/ftplib.pyi index 6c33f1409822..76d9dc02a5da 100644 --- a/stdlib/ftplib.pyi +++ b/stdlib/ftplib.pyi @@ -1,11 +1,11 @@ import sys -from _typeshed import Self, SupportsRead, SupportsReadline +from _typeshed import SupportsRead, SupportsReadline from collections.abc import Callable, Iterable, Iterator from socket import socket from ssl import SSLContext from types import TracebackType from typing import Any, TextIO -from typing_extensions import Literal +from typing_extensions import Literal, Self __all__ = ["FTP", "error_reply", "error_temp", "error_perm", "error_proto", "all_errors", "FTP_TLS"] @@ -36,7 +36,7 @@ class FTP: lastresp: str file: TextIO | None encoding: str - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__( self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None ) -> None: ... diff --git a/stdlib/functools.pyi b/stdlib/functools.pyi index 1a7391d8cace..1214e349f605 100644 --- a/stdlib/functools.pyi +++ b/stdlib/functools.pyi @@ -1,9 +1,9 @@ import sys import types -from _typeshed import IdentityFunction, Self, SupportsAllComparisons, SupportsItems +from _typeshed import IdentityFunction, SupportsAllComparisons, SupportsItems from collections.abc import Callable, Hashable, Iterable, Sequence, Sized from typing import Any, Generic, NamedTuple, TypeVar, overload -from typing_extensions import Literal, TypeAlias, final +from typing_extensions import Literal, Self, TypeAlias, final if sys.version_info >= (3, 9): from types import GenericAlias @@ -79,7 +79,7 @@ class partial(Generic[_T]): def args(self) -> tuple[Any, ...]: ... @property def keywords(self) -> dict[str, Any]: ... - def __new__(cls: type[Self], __func: Callable[..., _T], *args: Any, **kwargs: Any) -> Self: ... + def __new__(cls, __func: Callable[..., _T], *args: Any, **kwargs: Any) -> Self: ... def __call__(__self, *args: Any, **kwargs: Any) -> _T: ... if sys.version_info >= (3, 9): def __class_getitem__(cls, item: Any) -> GenericAlias: ... diff --git a/stdlib/hashlib.pyi b/stdlib/hashlib.pyi index 8292e319330a..18b1ab549764 100644 --- a/stdlib/hashlib.pyi +++ b/stdlib/hashlib.pyi @@ -1,8 +1,8 @@ import sys -from _typeshed import ReadableBuffer, Self +from _typeshed import ReadableBuffer from collections.abc import Callable, Set as AbstractSet from typing import Protocol -from typing_extensions import final +from typing_extensions import Self, final if sys.version_info >= (3, 11): __all__ = ( @@ -56,7 +56,7 @@ class _Hash: @property def name(self) -> str: ... def __init__(self, data: ReadableBuffer = ...) -> None: ... - def copy(self: Self) -> Self: ... + def copy(self) -> Self: ... def digest(self) -> bytes: ... def hexdigest(self) -> str: ... def update(self, __data: ReadableBuffer) -> None: ... diff --git a/stdlib/http/client.pyi b/stdlib/http/client.pyi index bb641875e55b..b1506b50e750 100644 --- a/stdlib/http/client.pyi +++ b/stdlib/http/client.pyi @@ -2,11 +2,11 @@ import email.message import io import ssl import types -from _typeshed import ReadableBuffer, Self, SupportsRead, WriteableBuffer +from _typeshed import ReadableBuffer, SupportsRead, WriteableBuffer from collections.abc import Callable, Iterable, Iterator, Mapping from socket import socket from typing import Any, BinaryIO, TypeVar, overload -from typing_extensions import TypeAlias +from typing_extensions import Self, TypeAlias __all__ = [ "HTTPResponse", @@ -127,7 +127,7 @@ class HTTPResponse(io.BufferedIOBase, BinaryIO): def getheaders(self) -> list[tuple[str, str]]: ... def isclosed(self) -> bool: ... def __iter__(self) -> Iterator[bytes]: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__( self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: types.TracebackType | None ) -> None: ... diff --git a/stdlib/imaplib.pyi b/stdlib/imaplib.pyi index 8016d8bec5cd..1c2112dd37c8 100644 --- a/stdlib/imaplib.pyi +++ b/stdlib/imaplib.pyi @@ -1,7 +1,7 @@ import subprocess import sys import time -from _typeshed import ReadableBuffer, Self, _BufferWithLen +from _typeshed import ReadableBuffer, _BufferWithLen from builtins import list as _list # conflicts with a method named "list" from collections.abc import Callable from datetime import datetime @@ -10,7 +10,7 @@ from socket import socket as _socket from ssl import SSLContext, SSLSocket from types import TracebackType from typing import IO, Any, SupportsAbs, SupportsInt -from typing_extensions import Literal, TypeAlias +from typing_extensions import Literal, Self, TypeAlias __all__ = ["IMAP4", "IMAP4_stream", "Internaldate2tuple", "Int2AP", "ParseFlags", "Time2Internaldate", "IMAP4_SSL"] @@ -69,7 +69,7 @@ class IMAP4: def delete(self, mailbox: str) -> _CommandResults: ... def deleteacl(self, mailbox: str, who: str) -> _CommandResults: ... def enable(self, capability: str) -> _CommandResults: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__(self, t: type[BaseException] | None, v: BaseException | None, tb: TracebackType | None) -> None: ... def expunge(self) -> _CommandResults: ... def fetch(self, message_set: str, message_parts: str) -> tuple[str, _AnyResponseData]: ... diff --git a/stdlib/importlib/metadata/__init__.pyi b/stdlib/importlib/metadata/__init__.pyi index 8c4ee3774b45..083453cd3c9a 100644 --- a/stdlib/importlib/metadata/__init__.pyi +++ b/stdlib/importlib/metadata/__init__.pyi @@ -1,7 +1,7 @@ import abc import pathlib import sys -from _typeshed import Self, StrPath +from _typeshed import StrPath from collections.abc import Iterable, Mapping from email.message import Message from importlib.abc import MetaPathFinder @@ -9,6 +9,7 @@ from os import PathLike from pathlib import Path from re import Pattern from typing import Any, ClassVar, NamedTuple, overload +from typing_extensions import Self __all__ = [ "Distribution", @@ -86,13 +87,13 @@ if sys.version_info >= (3, 10): class SelectableGroups(dict[str, EntryPoints]): # use as dict is deprecated since 3.10 @classmethod - def load(cls: type[Self], eps: Iterable[EntryPoint]) -> Self: ... + def load(cls, eps: Iterable[EntryPoint]) -> Self: ... @property def groups(self) -> set[str]: ... @property def names(self) -> set[str]: ... @overload - def select(self: Self) -> Self: ... # type: ignore[misc] + def select(self) -> Self: ... # type: ignore[misc] @overload def select( self, diff --git a/stdlib/inspect.pyi b/stdlib/inspect.pyi index 5fa806bca988..2525ef4968ec 100644 --- a/stdlib/inspect.pyi +++ b/stdlib/inspect.pyi @@ -2,7 +2,6 @@ import dis import enum import sys import types -from _typeshed import Self from collections import OrderedDict from collections.abc import AsyncGenerator, Awaitable, Callable, Coroutine, Generator, Mapping, Sequence, Set as AbstractSet from types import ( @@ -26,7 +25,7 @@ from types import ( WrapperDescriptorType, ) from typing import Any, ClassVar, NamedTuple, Protocol, TypeVar, overload -from typing_extensions import Literal, ParamSpec, TypeAlias, TypeGuard +from typing_extensions import Literal, ParamSpec, Self, TypeAlias, TypeGuard if sys.version_info >= (3, 11): __all__ = [ @@ -313,13 +312,11 @@ class Signature: def return_annotation(self) -> Any: ... def bind(self, *args: Any, **kwargs: Any) -> BoundArguments: ... def bind_partial(self, *args: Any, **kwargs: Any) -> BoundArguments: ... - def replace( - self: Self, *, parameters: Sequence[Parameter] | type[_void] | None = ..., return_annotation: Any = ... - ) -> Self: ... + def replace(self, *, parameters: Sequence[Parameter] | type[_void] | None = ..., return_annotation: Any = ...) -> Self: ... if sys.version_info >= (3, 10): @classmethod def from_callable( - cls: type[Self], + cls, obj: _IntrospectableCallable, *, follow_wrapped: bool = True, @@ -329,7 +326,7 @@ class Signature: ) -> Self: ... else: @classmethod - def from_callable(cls: type[Self], obj: _IntrospectableCallable, *, follow_wrapped: bool = True) -> Self: ... + def from_callable(cls, obj: _IntrospectableCallable, *, follow_wrapped: bool = True) -> Self: ... def __eq__(self, other: object) -> bool: ... @@ -372,7 +369,7 @@ class Parameter: @property def annotation(self) -> Any: ... def replace( - self: Self, + self, *, name: str | type[_void] = ..., kind: _ParameterKind | type[_void] = ..., @@ -493,7 +490,7 @@ if sys.version_info >= (3, 11): class Traceback(_Traceback): positions: dis.Positions | None def __new__( - cls: type[Self], + cls, filename: str, lineno: int, function: str, @@ -514,7 +511,7 @@ if sys.version_info >= (3, 11): class FrameInfo(_FrameInfo): positions: dis.Positions | None def __new__( - cls: type[Self], + cls, frame: FrameType, filename: str, lineno: int, diff --git a/stdlib/io.pyi b/stdlib/io.pyi index 6e1b4be77b07..c3e07bacbe5a 100644 --- a/stdlib/io.pyi +++ b/stdlib/io.pyi @@ -2,12 +2,12 @@ import abc import builtins import codecs import sys -from _typeshed import FileDescriptorOrPath, ReadableBuffer, Self, WriteableBuffer +from _typeshed import FileDescriptorOrPath, ReadableBuffer, WriteableBuffer from collections.abc import Callable, Iterable, Iterator from os import _Opener from types import TracebackType from typing import IO, Any, BinaryIO, TextIO -from typing_extensions import Literal +from typing_extensions import Literal, Self __all__ = [ "BlockingIOError", @@ -51,7 +51,7 @@ class UnsupportedOperation(OSError, ValueError): ... class IOBase(metaclass=abc.ABCMeta): def __iter__(self) -> Iterator[bytes]: ... def __next__(self) -> bytes: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__( self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None ) -> None: ... @@ -100,7 +100,7 @@ class FileIO(RawIOBase, BinaryIO): def closefd(self) -> bool: ... def write(self, __b: ReadableBuffer) -> int: ... def read(self, __size: int = -1) -> bytes: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... class BytesIO(BufferedIOBase, BinaryIO): def __init__(self, initial_bytes: ReadableBuffer = ...) -> None: ... @@ -108,23 +108,23 @@ class BytesIO(BufferedIOBase, BinaryIO): # to allow BytesIO sub-classes to add this field, as it is defined # as a read-only property on IO[]. name: Any - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def getvalue(self) -> bytes: ... def getbuffer(self) -> memoryview: ... def read1(self, __size: int | None = -1) -> bytes: ... class BufferedReader(BufferedIOBase, BinaryIO): - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __init__(self, raw: RawIOBase, buffer_size: int = ...) -> None: ... def peek(self, __size: int = 0) -> bytes: ... class BufferedWriter(BufferedIOBase, BinaryIO): - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __init__(self, raw: RawIOBase, buffer_size: int = ...) -> None: ... def write(self, __buffer: ReadableBuffer) -> int: ... class BufferedRandom(BufferedReader, BufferedWriter): - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def seek(self, __target: int, __whence: int = 0) -> int: ... # stubtest needs this class BufferedRWPair(BufferedIOBase): @@ -172,7 +172,7 @@ class TextIOWrapper(TextIOBase, TextIO): write_through: bool | None = None, ) -> None: ... # These are inherited from TextIOBase, but must exist in the stub to satisfy mypy. - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __iter__(self) -> Iterator[str]: ... # type: ignore[override] def __next__(self) -> str: ... # type: ignore[override] def writelines(self, __lines: Iterable[str]) -> None: ... # type: ignore[override] diff --git a/stdlib/ipaddress.pyi b/stdlib/ipaddress.pyi index 1de945db5d30..9f9662137765 100644 --- a/stdlib/ipaddress.pyi +++ b/stdlib/ipaddress.pyi @@ -1,8 +1,7 @@ import sys -from _typeshed import Self from collections.abc import Container, Iterable, Iterator from typing import Any, Generic, SupportsInt, TypeVar, overload -from typing_extensions import Literal, TypeAlias +from typing_extensions import Literal, Self, TypeAlias # Undocumented length constants IPV4LENGTH: Literal[32] @@ -34,20 +33,20 @@ class _IPAddressBase: class _BaseAddress(_IPAddressBase, SupportsInt): def __init__(self, address: object) -> None: ... - def __add__(self: Self, other: int) -> Self: ... + def __add__(self, other: int) -> Self: ... def __int__(self) -> int: ... - def __sub__(self: Self, other: int) -> Self: ... + def __sub__(self, other: int) -> Self: ... def __format__(self, fmt: str) -> str: ... def __eq__(self, other: object) -> bool: ... - def __lt__(self: Self, other: Self) -> bool: ... + def __lt__(self, other: Self) -> bool: ... if sys.version_info >= (3, 11): - def __ge__(self: Self, other: Self) -> bool: ... - def __gt__(self: Self, other: Self) -> bool: ... - def __le__(self: Self, other: Self) -> bool: ... + def __ge__(self, other: Self) -> bool: ... + def __gt__(self, other: Self) -> bool: ... + def __le__(self, other: Self) -> bool: ... else: - def __ge__(self: Self, other: Self, NotImplemented: Any = ...) -> bool: ... - def __gt__(self: Self, other: Self, NotImplemented: Any = ...) -> bool: ... - def __le__(self: Self, other: Self, NotImplemented: Any = ...) -> bool: ... + def __ge__(self, other: Self, NotImplemented: Any = ...) -> bool: ... + def __gt__(self, other: Self, NotImplemented: Any = ...) -> bool: ... + def __le__(self, other: Self, NotImplemented: Any = ...) -> bool: ... @property def is_global(self) -> bool: ... @@ -76,20 +75,20 @@ class _BaseNetwork(_IPAddressBase, Container[_A], Iterable[_A], Generic[_A]): def __getitem__(self, n: int) -> _A: ... def __iter__(self) -> Iterator[_A]: ... def __eq__(self, other: object) -> bool: ... - def __lt__(self: Self, other: Self) -> bool: ... + def __lt__(self, other: Self) -> bool: ... if sys.version_info >= (3, 11): - def __ge__(self: Self, other: Self) -> bool: ... - def __gt__(self: Self, other: Self) -> bool: ... - def __le__(self: Self, other: Self) -> bool: ... + def __ge__(self, other: Self) -> bool: ... + def __gt__(self, other: Self) -> bool: ... + def __le__(self, other: Self) -> bool: ... else: - def __ge__(self: Self, other: Self, NotImplemented: Any = ...) -> bool: ... - def __gt__(self: Self, other: Self, NotImplemented: Any = ...) -> bool: ... - def __le__(self: Self, other: Self, NotImplemented: Any = ...) -> bool: ... + def __ge__(self, other: Self, NotImplemented: Any = ...) -> bool: ... + def __gt__(self, other: Self, NotImplemented: Any = ...) -> bool: ... + def __le__(self, other: Self, NotImplemented: Any = ...) -> bool: ... - def address_exclude(self: Self, other: Self) -> Iterator[Self]: ... + def address_exclude(self, other: Self) -> Iterator[Self]: ... @property def broadcast_address(self) -> _A: ... - def compare_networks(self: Self, other: Self) -> int: ... + def compare_networks(self, other: Self) -> int: ... def hosts(self) -> Iterator[_A]: ... @property def is_global(self) -> bool: ... @@ -112,10 +111,10 @@ class _BaseNetwork(_IPAddressBase, Container[_A], Iterable[_A], Generic[_A]): def overlaps(self, other: _BaseNetwork[IPv4Address] | _BaseNetwork[IPv6Address]) -> bool: ... @property def prefixlen(self) -> int: ... - def subnet_of(self: Self, other: Self) -> bool: ... - def supernet_of(self: Self, other: Self) -> bool: ... - def subnets(self: Self, prefixlen_diff: int = 1, new_prefix: int | None = None) -> Iterator[Self]: ... - def supernet(self: Self, prefixlen_diff: int = 1, new_prefix: int | None = None) -> Self: ... + def subnet_of(self, other: Self) -> bool: ... + def supernet_of(self, other: Self) -> bool: ... + def subnets(self, prefixlen_diff: int = 1, new_prefix: int | None = None) -> Iterator[Self]: ... + def supernet(self, prefixlen_diff: int = 1, new_prefix: int | None = None) -> Self: ... @property def with_hostmask(self) -> str: ... @property diff --git a/stdlib/itertools.pyi b/stdlib/itertools.pyi index bea946376a5c..c7b92c3aebb5 100644 --- a/stdlib/itertools.pyi +++ b/stdlib/itertools.pyi @@ -1,8 +1,7 @@ import sys -from _typeshed import Self from collections.abc import Callable, Iterable, Iterator from typing import Any, Generic, SupportsComplex, SupportsFloat, SupportsInt, TypeVar, overload -from typing_extensions import Literal, SupportsIndex, TypeAlias +from typing_extensions import Literal, Self, SupportsIndex, TypeAlias if sys.version_info >= (3, 9): from types import GenericAlias @@ -32,12 +31,12 @@ class count(Iterator[_N], Generic[_N]): @overload def __new__(cls, *, step: _N) -> count[_N]: ... def __next__(self) -> _N: ... - def __iter__(self: Self) -> Self: ... + def __iter__(self) -> Self: ... class cycle(Iterator[_T], Generic[_T]): def __init__(self, __iterable: Iterable[_T]) -> None: ... def __next__(self) -> _T: ... - def __iter__(self: Self) -> Self: ... + def __iter__(self) -> Self: ... class repeat(Iterator[_T], Generic[_T]): @overload @@ -45,7 +44,7 @@ class repeat(Iterator[_T], Generic[_T]): @overload def __init__(self, object: _T, times: int) -> None: ... def __next__(self) -> _T: ... - def __iter__(self: Self) -> Self: ... + def __iter__(self) -> Self: ... def __length_hint__(self) -> int: ... class accumulate(Iterator[_T], Generic[_T]): @@ -57,13 +56,13 @@ class accumulate(Iterator[_T], Generic[_T]): else: def __init__(self, iterable: Iterable[_T], func: Callable[[_T, _T], _T] | None = ...) -> None: ... - def __iter__(self: Self) -> Self: ... + def __iter__(self) -> Self: ... def __next__(self) -> _T: ... class chain(Iterator[_T], Generic[_T]): def __init__(self, *iterables: Iterable[_T]) -> None: ... def __next__(self) -> _T: ... - def __iter__(self: Self) -> Self: ... + def __iter__(self) -> Self: ... @classmethod # We use type[Any] and not type[_S] to not lose the type inference from __iterable def from_iterable(cls: type[Any], __iterable: Iterable[Iterable[_S]]) -> chain[_S]: ... @@ -72,17 +71,17 @@ class chain(Iterator[_T], Generic[_T]): class compress(Iterator[_T], Generic[_T]): def __init__(self, data: Iterable[_T], selectors: Iterable[Any]) -> None: ... - def __iter__(self: Self) -> Self: ... + def __iter__(self) -> Self: ... def __next__(self) -> _T: ... class dropwhile(Iterator[_T], Generic[_T]): def __init__(self, __predicate: _Predicate[_T], __iterable: Iterable[_T]) -> None: ... - def __iter__(self: Self) -> Self: ... + def __iter__(self) -> Self: ... def __next__(self) -> _T: ... class filterfalse(Iterator[_T], Generic[_T]): def __init__(self, __predicate: _Predicate[_T] | None, __iterable: Iterable[_T]) -> None: ... - def __iter__(self: Self) -> Self: ... + def __iter__(self) -> Self: ... def __next__(self) -> _T: ... class groupby(Iterator[tuple[_T, Iterator[_S]]], Generic[_T, _S]): @@ -90,7 +89,7 @@ class groupby(Iterator[tuple[_T, Iterator[_S]]], Generic[_T, _S]): def __new__(cls, iterable: Iterable[_T1], key: None = None) -> groupby[_T1, _T1]: ... @overload def __new__(cls, iterable: Iterable[_T1], key: Callable[[_T1], _T2]) -> groupby[_T2, _T1]: ... - def __iter__(self: Self) -> Self: ... + def __iter__(self) -> Self: ... def __next__(self) -> tuple[_T, Iterator[_S]]: ... class islice(Iterator[_T], Generic[_T]): @@ -98,17 +97,17 @@ class islice(Iterator[_T], Generic[_T]): def __init__(self, __iterable: Iterable[_T], __stop: int | None) -> None: ... @overload def __init__(self, __iterable: Iterable[_T], __start: int | None, __stop: int | None, __step: int | None = ...) -> None: ... - def __iter__(self: Self) -> Self: ... + def __iter__(self) -> Self: ... def __next__(self) -> _T: ... class starmap(Iterator[_T], Generic[_T]): def __init__(self, __function: Callable[..., _T], __iterable: Iterable[Iterable[Any]]) -> None: ... - def __iter__(self: Self) -> Self: ... + def __iter__(self) -> Self: ... def __next__(self) -> _T: ... class takewhile(Iterator[_T], Generic[_T]): def __init__(self, __predicate: _Predicate[_T], __iterable: Iterable[_T]) -> None: ... - def __iter__(self: Self) -> Self: ... + def __iter__(self) -> Self: ... def __next__(self) -> _T: ... def tee(__iterable: Iterable[_T], __n: int = 2) -> tuple[Iterator[_T], ...]: ... @@ -190,7 +189,7 @@ class zip_longest(Iterator[_T_co], Generic[_T_co]): *iterables: Iterable[_T], fillvalue: _T, ) -> zip_longest[tuple[_T, ...]]: ... - def __iter__(self: Self) -> Self: ... + def __iter__(self) -> Self: ... def __next__(self) -> _T_co: ... class product(Iterator[_T_co], Generic[_T_co]): @@ -239,12 +238,12 @@ class product(Iterator[_T_co], Generic[_T_co]): def __new__(cls, *iterables: Iterable[_T1], repeat: int) -> product[tuple[_T1, ...]]: ... @overload def __new__(cls, *iterables: Iterable[Any], repeat: int = ...) -> product[tuple[Any, ...]]: ... - def __iter__(self: Self) -> Self: ... + def __iter__(self) -> Self: ... def __next__(self) -> _T_co: ... class permutations(Iterator[tuple[_T, ...]], Generic[_T]): def __init__(self, iterable: Iterable[_T], r: int | None = ...) -> None: ... - def __iter__(self: Self) -> Self: ... + def __iter__(self) -> Self: ... def __next__(self) -> tuple[_T, ...]: ... class combinations(Iterator[_T_co], Generic[_T_co]): @@ -258,22 +257,22 @@ class combinations(Iterator[_T_co], Generic[_T_co]): def __new__(cls, iterable: Iterable[_T], r: Literal[5]) -> combinations[tuple[_T, _T, _T, _T, _T]]: ... @overload def __new__(cls, iterable: Iterable[_T], r: int) -> combinations[tuple[_T, ...]]: ... - def __iter__(self: Self) -> Self: ... + def __iter__(self) -> Self: ... def __next__(self) -> _T_co: ... class combinations_with_replacement(Iterator[tuple[_T, ...]], Generic[_T]): def __init__(self, iterable: Iterable[_T], r: int) -> None: ... - def __iter__(self: Self) -> Self: ... + def __iter__(self) -> Self: ... def __next__(self) -> tuple[_T, ...]: ... if sys.version_info >= (3, 10): class pairwise(Iterator[_T_co], Generic[_T_co]): def __new__(cls, __iterable: Iterable[_T]) -> pairwise[tuple[_T, _T]]: ... - def __iter__(self: Self) -> Self: ... + def __iter__(self) -> Self: ... def __next__(self) -> _T_co: ... if sys.version_info >= (3, 12): class batched(Iterator[_T_co], Generic[_T_co]): - def __new__(cls: type[Self], iterable: Iterable[_T_co], n: int) -> Self: ... - def __iter__(self: Self) -> Self: ... + def __new__(cls, iterable: Iterable[_T_co], n: int) -> Self: ... + def __iter__(self) -> Self: ... def __next__(self) -> tuple[_T_co, ...]: ... diff --git a/stdlib/lib2to3/pgen2/grammar.pyi b/stdlib/lib2to3/pgen2/grammar.pyi index aa0dd687659d..bef0a7922683 100644 --- a/stdlib/lib2to3/pgen2/grammar.pyi +++ b/stdlib/lib2to3/pgen2/grammar.pyi @@ -1,5 +1,5 @@ -from _typeshed import Self, StrPath -from typing_extensions import TypeAlias +from _typeshed import StrPath +from typing_extensions import Self, TypeAlias _Label: TypeAlias = tuple[int, str | None] _DFA: TypeAlias = list[list[tuple[int, int]]] @@ -17,7 +17,7 @@ class Grammar: start: int def dump(self, filename: StrPath) -> None: ... def load(self, filename: StrPath) -> None: ... - def copy(self: Self) -> Self: ... + def copy(self) -> Self: ... def report(self) -> None: ... opmap_raw: str diff --git a/stdlib/lib2to3/pytree.pyi b/stdlib/lib2to3/pytree.pyi index 5cf7db146e46..4f756c9768db 100644 --- a/stdlib/lib2to3/pytree.pyi +++ b/stdlib/lib2to3/pytree.pyi @@ -1,8 +1,7 @@ -from _typeshed import Self from collections.abc import Iterator from lib2to3.pgen2.grammar import Grammar from typing import Any -from typing_extensions import TypeAlias +from typing_extensions import Self, TypeAlias _NL: TypeAlias = Node | Leaf _Context: TypeAlias = tuple[str, int, int] @@ -21,8 +20,8 @@ class Base: was_changed: bool was_checked: bool def __eq__(self, other: object) -> bool: ... - def _eq(self: Self, other: Self) -> bool: ... - def clone(self: Self) -> Self: ... + def _eq(self, other: Self) -> bool: ... + def clone(self) -> Self: ... def post_order(self) -> Iterator[_NL]: ... def pre_order(self) -> Iterator[_NL]: ... def replace(self, new: _NL | list[_NL]) -> None: ... diff --git a/stdlib/logging/__init__.pyi b/stdlib/logging/__init__.pyi index b68eb201df40..c74afa45ded1 100644 --- a/stdlib/logging/__init__.pyi +++ b/stdlib/logging/__init__.pyi @@ -1,6 +1,6 @@ import sys import threading -from _typeshed import Self, StrPath, SupportsWrite +from _typeshed import StrPath, SupportsWrite from collections.abc import Callable, Iterable, Mapping, MutableMapping, Sequence from io import TextIOWrapper from re import Pattern @@ -8,7 +8,7 @@ from string import Template from time import struct_time from types import FrameType, TracebackType from typing import Any, ClassVar, Generic, TextIO, TypeVar, overload -from typing_extensions import Literal, TypeAlias +from typing_extensions import Literal, Self, TypeAlias if sys.version_info >= (3, 11): from types import GenericAlias @@ -110,7 +110,7 @@ class Logger(Filterer): def setLevel(self, level: _Level) -> None: ... def isEnabledFor(self, level: int) -> bool: ... def getEffectiveLevel(self) -> int: ... - def getChild(self: Self, suffix: str) -> Self: ... # see python/typing#980 + def getChild(self, suffix: str) -> Self: ... # see python/typing#980 if sys.version_info >= (3, 8): def debug( self, diff --git a/stdlib/lzma.pyi b/stdlib/lzma.pyi index 2feb28a8e743..34bd6f3f8db1 100644 --- a/stdlib/lzma.pyi +++ b/stdlib/lzma.pyi @@ -1,8 +1,8 @@ import io -from _typeshed import ReadableBuffer, Self, StrOrBytesPath +from _typeshed import ReadableBuffer, StrOrBytesPath from collections.abc import Mapping, Sequence from typing import IO, Any, TextIO, overload -from typing_extensions import Literal, TypeAlias, final +from typing_extensions import Literal, Self, TypeAlias, final __all__ = [ "CHECK_NONE", @@ -115,7 +115,7 @@ class LZMAFile(io.BufferedIOBase, IO[bytes]): preset: int | None = None, filters: _FilterChain | None = None, ) -> None: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def peek(self, size: int = -1) -> bytes: ... def read(self, size: int | None = -1) -> bytes: ... def read1(self, size: int = -1) -> bytes: ... diff --git a/stdlib/mailbox.pyi b/stdlib/mailbox.pyi index 2fe9060e7b7c..8053fad88ea5 100644 --- a/stdlib/mailbox.pyi +++ b/stdlib/mailbox.pyi @@ -1,12 +1,12 @@ import email.message import io import sys -from _typeshed import Self, StrPath, SupportsNoArgReadline, SupportsRead +from _typeshed import StrPath, SupportsNoArgReadline, SupportsRead from abc import ABCMeta, abstractmethod from collections.abc import Callable, Iterable, Iterator, Mapping, Sequence from types import TracebackType from typing import IO, Any, AnyStr, Generic, Protocol, TypeVar, overload -from typing_extensions import Literal, TypeAlias +from typing_extensions import Literal, Self, TypeAlias if sys.version_info >= (3, 9): from types import GenericAlias @@ -235,7 +235,7 @@ class _ProxyFile(Generic[AnyStr]): def tell(self) -> int: ... def seek(self, offset: int, whence: int = 0) -> None: ... def close(self) -> None: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__(self, exc_type: type[BaseException] | None, exc: BaseException | None, tb: TracebackType | None) -> None: ... def readable(self) -> bool: ... def writable(self) -> bool: ... diff --git a/stdlib/mmap.pyi b/stdlib/mmap.pyi index 273cd0c6f4d4..c74ad3cda6db 100644 --- a/stdlib/mmap.pyi +++ b/stdlib/mmap.pyi @@ -1,7 +1,8 @@ import sys -from _typeshed import ReadableBuffer, Self, Unused +from _typeshed import ReadableBuffer, Unused from collections.abc import Iterable, Iterator, Sized from typing import NoReturn, overload +from typing_extensions import Self ACCESS_DEFAULT: int ACCESS_READ: int @@ -73,7 +74,7 @@ class mmap(Iterable[int], Sized): # Doesn't actually exist, but the object is actually iterable because it has __getitem__ and __len__, # so we claim that there is also an __iter__ to help type checkers. def __iter__(self) -> Iterator[int]: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__(self, *args: Unused) -> None: ... if sys.version_info >= (3, 8) and sys.platform != "win32": diff --git a/stdlib/multiprocessing/connection.pyi b/stdlib/multiprocessing/connection.pyi index 868921f8b1d2..d034373712e0 100644 --- a/stdlib/multiprocessing/connection.pyi +++ b/stdlib/multiprocessing/connection.pyi @@ -1,10 +1,10 @@ import socket import sys import types -from _typeshed import ReadableBuffer, Self +from _typeshed import ReadableBuffer from collections.abc import Iterable from typing import Any -from typing_extensions import SupportsIndex, TypeAlias +from typing_extensions import Self, SupportsIndex, TypeAlias __all__ = ["Client", "Listener", "Pipe", "wait"] @@ -27,7 +27,7 @@ class _ConnectionBase: def recv_bytes_into(self, buf: Any, offset: int = 0) -> int: ... def recv(self) -> Any: ... def poll(self, timeout: float | None = 0.0) -> bool: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__( self, exc_type: type[BaseException] | None, exc_value: BaseException | None, exc_tb: types.TracebackType | None ) -> None: ... @@ -47,7 +47,7 @@ class Listener: def address(self) -> _Address: ... @property def last_accepted(self) -> _Address | None: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__( self, exc_type: type[BaseException] | None, exc_value: BaseException | None, exc_tb: types.TracebackType | None ) -> None: ... diff --git a/stdlib/multiprocessing/dummy/connection.pyi b/stdlib/multiprocessing/dummy/connection.pyi index 82a9027141fa..fcd03a657319 100644 --- a/stdlib/multiprocessing/dummy/connection.pyi +++ b/stdlib/multiprocessing/dummy/connection.pyi @@ -1,8 +1,7 @@ -from _typeshed import Self from queue import Queue from types import TracebackType from typing import Any -from typing_extensions import TypeAlias +from typing_extensions import Self, TypeAlias __all__ = ["Client", "Listener", "Pipe"] @@ -17,7 +16,7 @@ class Connection: recv_bytes: Any send: Any send_bytes: Any - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__( self, exc_type: type[BaseException] | None, exc_value: BaseException | None, exc_tb: TracebackType | None ) -> None: ... @@ -29,7 +28,7 @@ class Listener: _backlog_queue: Queue[Any] | None @property def address(self) -> Queue[Any] | None: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__( self, exc_type: type[BaseException] | None, exc_value: BaseException | None, exc_tb: TracebackType | None ) -> None: ... diff --git a/stdlib/multiprocessing/managers.pyi b/stdlib/multiprocessing/managers.pyi index baeabab94e11..e035a1875650 100644 --- a/stdlib/multiprocessing/managers.pyi +++ b/stdlib/multiprocessing/managers.pyi @@ -1,11 +1,11 @@ import queue import sys import threading -from _typeshed import Self, SupportsKeysAndGetItem, SupportsRichComparison, SupportsRichComparisonT +from _typeshed import SupportsKeysAndGetItem, SupportsRichComparison, SupportsRichComparisonT from collections.abc import Callable, Iterable, Iterator, Mapping, MutableMapping, MutableSequence, Sequence from types import TracebackType from typing import Any, AnyStr, ClassVar, Generic, TypeVar, overload -from typing_extensions import SupportsIndex, TypeAlias +from typing_extensions import Self, SupportsIndex, TypeAlias from .connection import Connection from .context import BaseContext @@ -116,8 +116,8 @@ class BaseListProxy(BaseProxy, MutableSequence[_T]): def sort(self, *, key: Callable[[_T], SupportsRichComparison], reverse: bool = ...) -> None: ... class ListProxy(BaseListProxy[_T]): - def __iadd__(self: Self, __x: Iterable[_T]) -> Self: ... # type: ignore[override] - def __imul__(self: Self, __n: SupportsIndex) -> Self: ... # type: ignore[override] + def __iadd__(self, __x: Iterable[_T]) -> Self: ... # type: ignore[override] + def __imul__(self, __n: SupportsIndex) -> Self: ... # type: ignore[override] # Returned by BaseManager.get_server() class Server: @@ -165,7 +165,7 @@ class BaseManager: method_to_typeid: Mapping[str, str] | None = None, create_method: bool = True, ) -> None: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__( self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None ) -> None: ... diff --git a/stdlib/multiprocessing/pool.pyi b/stdlib/multiprocessing/pool.pyi index 3e2d0c3cd51e..a19dd555e254 100644 --- a/stdlib/multiprocessing/pool.pyi +++ b/stdlib/multiprocessing/pool.pyi @@ -1,9 +1,8 @@ import sys -from _typeshed import Self from collections.abc import Callable, Iterable, Iterator, Mapping from types import TracebackType from typing import Any, Generic, TypeVar -from typing_extensions import Literal +from typing_extensions import Literal, Self if sys.version_info >= (3, 9): from types import GenericAlias @@ -62,7 +61,7 @@ class IMapIterator(Iterator[_T]): else: def __init__(self, cache: dict[int, IMapIterator[Any]]) -> None: ... - def __iter__(self: Self) -> Self: ... + def __iter__(self) -> Self: ... def next(self, timeout: float | None = None) -> _T: ... def __next__(self, timeout: float | None = None) -> _T: ... @@ -109,7 +108,7 @@ class Pool: def close(self) -> None: ... def terminate(self) -> None: ... def join(self) -> None: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__( self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None ) -> None: ... diff --git a/stdlib/multiprocessing/shared_memory.pyi b/stdlib/multiprocessing/shared_memory.pyi index 841c947360e8..ae6e2a0ed19f 100644 --- a/stdlib/multiprocessing/shared_memory.pyi +++ b/stdlib/multiprocessing/shared_memory.pyi @@ -1,7 +1,7 @@ import sys -from _typeshed import Self from collections.abc import Iterable from typing import Any, Generic, TypeVar, overload +from typing_extensions import Self if sys.version_info >= (3, 9): from types import GenericAlias @@ -29,7 +29,7 @@ class ShareableList(Generic[_SLT]): def __init__(self, sequence: Iterable[_SLT], *, name: str | None = None) -> None: ... def __getitem__(self, position: int) -> _SLT: ... def __setitem__(self, position: int, value: _SLT) -> None: ... - def __reduce__(self: Self) -> tuple[Self, tuple[_SLT, ...]]: ... + def __reduce__(self) -> tuple[Self, tuple[_SLT, ...]]: ... def __len__(self) -> int: ... @property def format(self) -> str: ... diff --git a/stdlib/nntplib.pyi b/stdlib/nntplib.pyi index 02e743ea9d1e..f948c1430c90 100644 --- a/stdlib/nntplib.pyi +++ b/stdlib/nntplib.pyi @@ -2,11 +2,11 @@ import datetime import socket import ssl import sys -from _typeshed import Self, Unused +from _typeshed import Unused from builtins import list as _list # conflicts with a method named "list" from collections.abc import Iterable from typing import IO, Any, NamedTuple -from typing_extensions import Literal, TypeAlias +from typing_extensions import Literal, Self, TypeAlias __all__ = [ "NNTP", @@ -72,7 +72,7 @@ class NNTP: usenetrc: bool = False, timeout: float = ..., ) -> None: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__(self, *args: Unused) -> None: ... def getwelcome(self) -> str: ... def getcapabilities(self) -> dict[str, _list[str]]: ... diff --git a/stdlib/os/__init__.pyi b/stdlib/os/__init__.pyi index 23c167c4544f..595b78789c6a 100644 --- a/stdlib/os/__init__.pyi +++ b/stdlib/os/__init__.pyi @@ -11,7 +11,6 @@ from _typeshed import ( OpenBinaryModeWriting, OpenTextMode, ReadableBuffer, - Self, StrOrBytesPath, StrPath, SupportsLenAndGetItem, @@ -26,7 +25,7 @@ from contextlib import AbstractContextManager from io import BufferedRandom, BufferedReader, BufferedWriter, FileIO, TextIOWrapper as _TextIOWrapper from subprocess import Popen from typing import IO, Any, AnyStr, BinaryIO, Generic, NoReturn, Protocol, TypeVar, overload, runtime_checkable -from typing_extensions import Final, Literal, TypeAlias, final +from typing_extensions import Final, Literal, Self, TypeAlias, final from . import path as _path @@ -245,9 +244,9 @@ class _Environ(MutableMapping[AnyStr, AnyStr], Generic[AnyStr]): # overloading MutableMapping.update in stdlib/typing.pyi # The type: ignore is needed due to incompatible __or__/__ior__ signatures @overload # type: ignore[misc] - def __ior__(self: Self, other: Mapping[AnyStr, AnyStr]) -> Self: ... + def __ior__(self, other: Mapping[AnyStr, AnyStr]) -> Self: ... @overload - def __ior__(self: Self, other: Iterable[tuple[AnyStr, AnyStr]]) -> Self: ... + def __ior__(self, other: Iterable[tuple[AnyStr, AnyStr]]) -> Self: ... environ: _Environ[str] if sys.platform != "win32": @@ -958,7 +957,7 @@ if sys.platform != "win32": class sched_param(structseq[int], tuple[int]): if sys.version_info >= (3, 10): __match_args__: Final = ("sched_priority",) - def __new__(cls: type[Self], sched_priority: int) -> Self: ... + def __new__(cls, sched_priority: int) -> Self: ... @property def sched_priority(self) -> int: ... @@ -1001,7 +1000,7 @@ if sys.version_info >= (3, 8): path: str | None def __init__(self, path: str | None, cookie: _T, remove_dll_directory: Callable[[_T], object]) -> None: ... def close(self) -> None: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__(self, *args: Unused) -> None: ... def add_dll_directory(path: str) -> _AddedDllDirectory: ... diff --git a/stdlib/pathlib.pyi b/stdlib/pathlib.pyi index 5220a142fb13..114678ed574d 100644 --- a/stdlib/pathlib.pyi +++ b/stdlib/pathlib.pyi @@ -6,7 +6,6 @@ from _typeshed import ( OpenBinaryModeWriting, OpenTextMode, ReadableBuffer, - Self, StrOrBytesPath, StrPath, ) @@ -15,7 +14,7 @@ from io import BufferedRandom, BufferedReader, BufferedWriter, FileIO, TextIOWra from os import PathLike, stat_result from types import TracebackType from typing import IO, Any, BinaryIO, overload -from typing_extensions import Literal +from typing_extensions import Literal, Self if sys.version_info >= (3, 9): from types import GenericAlias @@ -39,15 +38,15 @@ class PurePath(PathLike[str]): def suffixes(self) -> list[str]: ... @property def stem(self) -> str: ... - def __new__(cls: type[Self], *args: StrPath) -> Self: ... + def __new__(cls, *args: StrPath) -> Self: ... def __eq__(self, other: object) -> bool: ... def __fspath__(self) -> str: ... def __lt__(self, other: PurePath) -> bool: ... def __le__(self, other: PurePath) -> bool: ... def __gt__(self, other: PurePath) -> bool: ... def __ge__(self, other: PurePath) -> bool: ... - def __truediv__(self: Self, key: StrPath) -> Self: ... - def __rtruediv__(self: Self, key: StrPath) -> Self: ... + def __truediv__(self, key: StrPath) -> Self: ... + def __rtruediv__(self, key: StrPath) -> Self: ... def __bytes__(self) -> bytes: ... def as_posix(self) -> str: ... def as_uri(self) -> str: ... @@ -57,17 +56,17 @@ class PurePath(PathLike[str]): def is_relative_to(self, *other: StrPath) -> bool: ... def match(self, path_pattern: str) -> bool: ... - def relative_to(self: Self, *other: StrPath) -> Self: ... - def with_name(self: Self, name: str) -> Self: ... + def relative_to(self, *other: StrPath) -> Self: ... + def with_name(self, name: str) -> Self: ... if sys.version_info >= (3, 9): - def with_stem(self: Self, stem: str) -> Self: ... + def with_stem(self, stem: str) -> Self: ... - def with_suffix(self: Self, suffix: str) -> Self: ... - def joinpath(self: Self, *other: StrPath) -> Self: ... + def with_suffix(self, suffix: str) -> Self: ... + def joinpath(self, *other: StrPath) -> Self: ... @property - def parents(self: Self) -> Sequence[Self]: ... + def parents(self) -> Sequence[Self]: ... @property - def parent(self: Self) -> Self: ... + def parent(self) -> Self: ... if sys.version_info >= (3, 9) and sys.version_info < (3, 11): def __class_getitem__(cls, type: Any) -> GenericAlias: ... @@ -75,11 +74,11 @@ class PurePosixPath(PurePath): ... class PureWindowsPath(PurePath): ... class Path(PurePath): - def __new__(cls: type[Self], *args: StrPath, **kwargs: Any) -> Self: ... - def __enter__(self: Self) -> Self: ... + def __new__(cls, *args: StrPath, **kwargs: Any) -> Self: ... + def __enter__(self) -> Self: ... def __exit__(self, t: type[BaseException] | None, v: BaseException | None, tb: TracebackType | None) -> None: ... @classmethod - def cwd(cls: type[Self]) -> Self: ... + def cwd(cls) -> Self: ... if sys.version_info >= (3, 10): def stat(self, *, follow_symlinks: bool = True) -> stat_result: ... def chmod(self, mode: int, *, follow_symlinks: bool = True) -> None: ... @@ -88,7 +87,7 @@ class Path(PurePath): def chmod(self, mode: int) -> None: ... def exists(self) -> bool: ... - def glob(self: Self, pattern: str) -> Generator[Self, None, None]: ... + def glob(self, pattern: str) -> Generator[Self, None, None]: ... def is_dir(self) -> bool: ... def is_file(self) -> bool: ... def is_symlink(self) -> bool: ... @@ -96,7 +95,7 @@ class Path(PurePath): def is_fifo(self) -> bool: ... def is_block_device(self) -> bool: ... def is_char_device(self) -> bool: ... - def iterdir(self: Self) -> Generator[Self, None, None]: ... + def iterdir(self) -> Generator[Self, None, None]: ... def lchmod(self, mode: int) -> None: ... def lstat(self) -> stat_result: ... def mkdir(self, mode: int = 0o777, parents: bool = False, exist_ok: bool = False) -> None: ... @@ -163,16 +162,16 @@ class Path(PurePath): def is_mount(self) -> bool: ... if sys.version_info >= (3, 9): - def readlink(self: Self) -> Self: ... + def readlink(self) -> Self: ... if sys.version_info >= (3, 8): - def rename(self: Self, target: str | PurePath) -> Self: ... - def replace(self: Self, target: str | PurePath) -> Self: ... + def rename(self, target: str | PurePath) -> Self: ... + def replace(self, target: str | PurePath) -> Self: ... else: def rename(self, target: str | PurePath) -> None: ... def replace(self, target: str | PurePath) -> None: ... - def resolve(self: Self, strict: bool = False) -> Self: ... - def rglob(self: Self, pattern: str) -> Generator[Self, None, None]: ... + def resolve(self, strict: bool = False) -> Self: ... + def rglob(self, pattern: str) -> Generator[Self, None, None]: ... def rmdir(self) -> None: ... def symlink_to(self, target: str | Path, target_is_directory: bool = False) -> None: ... if sys.version_info >= (3, 10): @@ -185,9 +184,9 @@ class Path(PurePath): def unlink(self) -> None: ... @classmethod - def home(cls: type[Self]) -> Self: ... - def absolute(self: Self) -> Self: ... - def expanduser(self: Self) -> Self: ... + def home(cls) -> Self: ... + def absolute(self) -> Self: ... + def expanduser(self) -> Self: ... def read_bytes(self) -> bytes: ... def read_text(self, encoding: str | None = None, errors: str | None = None) -> str: ... def samefile(self, other_path: StrPath) -> bool: ... @@ -202,7 +201,7 @@ class Path(PurePath): def link_to(self, target: StrOrBytesPath) -> None: ... if sys.version_info >= (3, 12): def walk( - self: Self, top_down: bool = ..., on_error: Callable[[OSError], object] | None = ..., follow_symlinks: bool = ... + self, top_down: bool = ..., on_error: Callable[[OSError], object] | None = ..., follow_symlinks: bool = ... ) -> Iterator[tuple[Self, list[str], list[str]]]: ... class PosixPath(Path, PurePosixPath): ... diff --git a/stdlib/pdb.pyi b/stdlib/pdb.pyi index a2b6636d8665..e2871bb54fa0 100644 --- a/stdlib/pdb.pyi +++ b/stdlib/pdb.pyi @@ -1,13 +1,12 @@ import signal import sys -from _typeshed import Self from bdb import Bdb from cmd import Cmd from collections.abc import Callable, Iterable, Mapping, Sequence from inspect import _SourceObjectType from types import CodeType, FrameType, TracebackType from typing import IO, Any, ClassVar, TypeVar -from typing_extensions import ParamSpec +from typing_extensions import ParamSpec, Self __all__ = ["run", "pm", "Pdb", "runeval", "runctx", "runcall", "set_trace", "post_mortem", "help"] @@ -173,4 +172,4 @@ def getsourcelines(obj: _SourceObjectType) -> tuple[list[str], int]: ... def lasti2lineno(code: CodeType, lasti: int) -> int: ... class _rstr(str): - def __repr__(self: Self) -> Self: ... + def __repr__(self) -> Self: ... diff --git a/stdlib/plistlib.pyi b/stdlib/plistlib.pyi index 54ce3dc61abc..5b76c935f76e 100644 --- a/stdlib/plistlib.pyi +++ b/stdlib/plistlib.pyi @@ -1,9 +1,10 @@ import sys -from _typeshed import ReadableBuffer, Self +from _typeshed import ReadableBuffer from collections.abc import Mapping, MutableMapping from datetime import datetime from enum import Enum from typing import IO, Any +from typing_extensions import Self if sys.version_info >= (3, 9): __all__ = ["InvalidFileException", "FMT_XML", "FMT_BINARY", "load", "dump", "loads", "dumps", "UID"] @@ -100,7 +101,7 @@ if sys.version_info >= (3, 8): data: int def __init__(self, data: int) -> None: ... def __index__(self) -> int: ... - def __reduce__(self: Self) -> tuple[type[Self], tuple[int]]: ... + def __reduce__(self) -> tuple[type[Self], tuple[int]]: ... def __eq__(self, other: object) -> bool: ... class InvalidFileException(ValueError): diff --git a/stdlib/profile.pyi b/stdlib/profile.pyi index 8d6e9b220587..6ae375004158 100644 --- a/stdlib/profile.pyi +++ b/stdlib/profile.pyi @@ -1,7 +1,7 @@ -from _typeshed import Self, StrOrBytesPath +from _typeshed import StrOrBytesPath from collections.abc import Callable from typing import Any, TypeVar -from typing_extensions import ParamSpec, TypeAlias +from typing_extensions import ParamSpec, Self, TypeAlias __all__ = ["run", "runctx", "Profile"] @@ -25,7 +25,7 @@ class Profile: def dump_stats(self, file: StrOrBytesPath) -> None: ... def create_stats(self) -> None: ... def snapshot_stats(self) -> None: ... - def run(self: Self, cmd: str) -> Self: ... - def runctx(self: Self, cmd: str, globals: dict[str, Any], locals: dict[str, Any]) -> Self: ... + def run(self, cmd: str) -> Self: ... + def runctx(self, cmd: str, globals: dict[str, Any], locals: dict[str, Any]) -> Self: ... def runcall(self, __func: Callable[_P, _T], *args: _P.args, **kw: _P.kwargs) -> _T: ... def calibrate(self, m: int, verbose: int = 0) -> float: ... diff --git a/stdlib/pstats.pyi b/stdlib/pstats.pyi index f4f331934565..5d25d1bb3641 100644 --- a/stdlib/pstats.pyi +++ b/stdlib/pstats.pyi @@ -1,11 +1,11 @@ import sys -from _typeshed import Self, StrOrBytesPath +from _typeshed import StrOrBytesPath from collections.abc import Iterable from cProfile import Profile as _cProfile from enum import Enum from profile import Profile from typing import IO, Any, overload -from typing_extensions import Literal, TypeAlias +from typing_extensions import Literal, Self, TypeAlias if sys.version_info >= (3, 9): __all__ = ["Stats", "SortKey", "FunctionProfile", "StatsProfile"] @@ -47,7 +47,7 @@ _SortArgDict: TypeAlias = dict[str, tuple[tuple[tuple[int, int], ...], str]] class Stats: sort_arg_dict_default: _SortArgDict def __init__( - self: Self, + self, __arg: None | str | Profile | _cProfile = ..., *args: None | str | Profile | _cProfile | Self, stream: IO[Any] | None = None, @@ -55,24 +55,24 @@ class Stats: def init(self, arg: None | str | Profile | _cProfile) -> None: ... def load_stats(self, arg: None | str | Profile | _cProfile) -> None: ... def get_top_level_stats(self) -> None: ... - def add(self: Self, *arg_list: None | str | Profile | _cProfile | Self) -> Self: ... + def add(self, *arg_list: None | str | Profile | _cProfile | Self) -> Self: ... def dump_stats(self, filename: StrOrBytesPath) -> None: ... def get_sort_arg_defs(self) -> _SortArgDict: ... @overload - def sort_stats(self: Self, field: Literal[-1, 0, 1, 2]) -> Self: ... + def sort_stats(self, field: Literal[-1, 0, 1, 2]) -> Self: ... @overload - def sort_stats(self: Self, *field: str) -> Self: ... - def reverse_order(self: Self) -> Self: ... - def strip_dirs(self: Self) -> Self: ... + def sort_stats(self, *field: str) -> Self: ... + def reverse_order(self) -> Self: ... + def strip_dirs(self) -> Self: ... def calc_callees(self) -> None: ... def eval_print_amount(self, sel: _Selector, list: list[str], msg: str) -> tuple[list[str], str]: ... if sys.version_info >= (3, 9): def get_stats_profile(self) -> StatsProfile: ... def get_print_list(self, sel_list: Iterable[_Selector]) -> tuple[int, list[str]]: ... - def print_stats(self: Self, *amount: _Selector) -> Self: ... - def print_callees(self: Self, *amount: _Selector) -> Self: ... - def print_callers(self: Self, *amount: _Selector) -> Self: ... + def print_stats(self, *amount: _Selector) -> Self: ... + def print_callees(self, *amount: _Selector) -> Self: ... + def print_callers(self, *amount: _Selector) -> Self: ... def print_call_heading(self, name_size: int, column_title: str) -> None: ... def print_call_line(self, name_size: int, source: str, call_dict: dict[str, Any], arrow: str = "->") -> None: ... def print_title(self) -> None: ... diff --git a/stdlib/runpy.pyi b/stdlib/runpy.pyi index 7efc194c8c66..d4406ea4ac41 100644 --- a/stdlib/runpy.pyi +++ b/stdlib/runpy.pyi @@ -1,6 +1,7 @@ -from _typeshed import Self, Unused +from _typeshed import Unused from types import ModuleType from typing import Any +from typing_extensions import Self __all__ = ["run_module", "run_path"] @@ -8,7 +9,7 @@ class _TempModule: mod_name: str module: ModuleType def __init__(self, mod_name: str) -> None: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__(self, *args: Unused) -> None: ... class _ModifiedArgv0: diff --git a/stdlib/select.pyi b/stdlib/select.pyi index d02651320cf6..412fd71ee38d 100644 --- a/stdlib/select.pyi +++ b/stdlib/select.pyi @@ -1,9 +1,9 @@ import sys -from _typeshed import FileDescriptorLike, Self +from _typeshed import FileDescriptorLike from collections.abc import Iterable from types import TracebackType from typing import Any -from typing_extensions import final +from typing_extensions import Self, final if sys.platform != "win32": PIPE_BUF: int @@ -106,7 +106,7 @@ if sys.platform == "linux": @final class epoll: def __init__(self, sizehint: int = ..., flags: int = ...) -> None: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__( self, __exc_type: type[BaseException] | None = None, diff --git a/stdlib/selectors.pyi b/stdlib/selectors.pyi index e15780fadee1..90a923f09355 100644 --- a/stdlib/selectors.pyi +++ b/stdlib/selectors.pyi @@ -1,9 +1,9 @@ import sys -from _typeshed import FileDescriptor, FileDescriptorLike, Self, Unused +from _typeshed import FileDescriptor, FileDescriptorLike, Unused from abc import ABCMeta, abstractmethod from collections.abc import Mapping from typing import Any, NamedTuple -from typing_extensions import TypeAlias +from typing_extensions import Self, TypeAlias _EventMask: TypeAlias = int @@ -28,7 +28,7 @@ class BaseSelector(metaclass=ABCMeta): def get_key(self, fileobj: FileDescriptorLike) -> SelectorKey: ... @abstractmethod def get_map(self) -> Mapping[FileDescriptorLike, SelectorKey]: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__(self, *args: Unused) -> None: ... class SelectSelector(BaseSelector): diff --git a/stdlib/shelve.pyi b/stdlib/shelve.pyi index d55e08bffa16..82d0b03f4049 100644 --- a/stdlib/shelve.pyi +++ b/stdlib/shelve.pyi @@ -1,8 +1,8 @@ -from _typeshed import Self from collections.abc import Iterator, MutableMapping from dbm import _TFlags from types import TracebackType from typing import Any, TypeVar, overload +from typing_extensions import Self __all__ = ["Shelf", "BsdDbShelf", "DbfilenameShelf", "open"] @@ -23,7 +23,7 @@ class Shelf(MutableMapping[str, _VT]): def __setitem__(self, key: str, value: _VT) -> None: ... def __delitem__(self, key: str) -> None: ... def __contains__(self, key: str) -> bool: ... # type: ignore[override] - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__( self, type: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None ) -> None: ... diff --git a/stdlib/shlex.pyi b/stdlib/shlex.pyi index 9a578d186be8..fa04932db676 100644 --- a/stdlib/shlex.pyi +++ b/stdlib/shlex.pyi @@ -1,7 +1,7 @@ import sys -from _typeshed import Self from collections.abc import Iterable from typing import TextIO +from typing_extensions import Self if sys.version_info >= (3, 8): __all__ = ["shlex", "split", "quote", "join"] @@ -46,5 +46,5 @@ class shlex(Iterable[str]): def push_source(self, newstream: str | TextIO, newfile: str | None = None) -> None: ... def pop_source(self) -> None: ... def error_leader(self, infile: str | None = None, lineno: int | None = None) -> None: ... - def __iter__(self: Self) -> Self: ... + def __iter__(self) -> Self: ... def __next__(self) -> str: ... diff --git a/stdlib/smtplib.pyi b/stdlib/smtplib.pyi index 63082f69d66b..0d7595fc1d6d 100644 --- a/stdlib/smtplib.pyi +++ b/stdlib/smtplib.pyi @@ -1,6 +1,6 @@ import sys from _socket import _Address as _SourceAddress -from _typeshed import ReadableBuffer, Self, _BufferWithLen +from _typeshed import ReadableBuffer, _BufferWithLen from collections.abc import Sequence from email.message import Message as _Message from re import Pattern @@ -8,7 +8,7 @@ from socket import socket from ssl import SSLContext from types import TracebackType from typing import Any, Protocol, overload -from typing_extensions import TypeAlias +from typing_extensions import Self, TypeAlias __all__ = [ "SMTPException", @@ -95,7 +95,7 @@ class SMTP: timeout: float = ..., source_address: _SourceAddress | None = None, ) -> None: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__( self, exc_type: type[BaseException] | None, exc_value: BaseException | None, tb: TracebackType | None ) -> None: ... diff --git a/stdlib/socket.pyi b/stdlib/socket.pyi index 4481f398867c..dbc1d46ec1d4 100644 --- a/stdlib/socket.pyi +++ b/stdlib/socket.pyi @@ -112,12 +112,12 @@ from _socket import ( setdefaulttimeout as setdefaulttimeout, timeout as timeout, ) -from _typeshed import ReadableBuffer, Self, Unused, WriteableBuffer +from _typeshed import ReadableBuffer, Unused, WriteableBuffer from collections.abc import Iterable from enum import IntEnum, IntFlag from io import BufferedReader, BufferedRWPair, BufferedWriter, IOBase, RawIOBase, TextIOWrapper from typing import Any, Protocol, overload -from typing_extensions import Literal +from typing_extensions import Literal, Self if sys.platform != "darwin" or sys.version_info >= (3, 9): from _socket import ( @@ -657,9 +657,9 @@ class socket(_socket.socket): def __init__( self, family: AddressFamily | int = -1, type: SocketKind | int = -1, proto: int = -1, fileno: int | None = None ) -> None: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__(self, *args: Unused) -> None: ... - def dup(self: Self) -> Self: ... # noqa: F811 + def dup(self) -> Self: ... # noqa: F811 def accept(self) -> tuple[socket, _RetAddress]: ... # Note that the makefile's documented windows-specific behavior is not represented # mode strings with duplicates are intentionally excluded diff --git a/stdlib/socketserver.pyi b/stdlib/socketserver.pyi index c74312cea6e6..3f0bb0eea0ce 100644 --- a/stdlib/socketserver.pyi +++ b/stdlib/socketserver.pyi @@ -1,11 +1,11 @@ import sys import types from _socket import _Address, _RetAddress -from _typeshed import ReadableBuffer, Self +from _typeshed import ReadableBuffer from collections.abc import Callable from socket import socket as _socket from typing import Any, BinaryIO, ClassVar -from typing_extensions import TypeAlias +from typing_extensions import Self, TypeAlias __all__ = [ "BaseServer", @@ -43,13 +43,13 @@ class BaseServer: socket_type: int timeout: float | None def __init__( - self: Self, server_address: _Address, RequestHandlerClass: Callable[[Any, _RetAddress, Self], BaseRequestHandler] + self, server_address: _Address, RequestHandlerClass: Callable[[Any, _RetAddress, Self], BaseRequestHandler] ) -> None: ... # It is not actually a `@property`, but we need a `Self` type: @property - def RequestHandlerClass(self: Self) -> Callable[[Any, _RetAddress, Self], BaseRequestHandler]: ... + def RequestHandlerClass(self) -> Callable[[Any, _RetAddress, Self], BaseRequestHandler]: ... @RequestHandlerClass.setter - def RequestHandlerClass(self: Self, val: Callable[[Any, _RetAddress, Self], BaseRequestHandler]) -> None: ... + def RequestHandlerClass(self, val: Callable[[Any, _RetAddress, Self], BaseRequestHandler]) -> None: ... def fileno(self) -> int: ... def handle_request(self) -> None: ... def serve_forever(self, poll_interval: float = 0.5) -> None: ... @@ -63,7 +63,7 @@ class BaseServer: def server_activate(self) -> None: ... def server_bind(self) -> None: ... def verify_request(self, request: _RequestType, client_address: _RetAddress) -> bool: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__( self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: types.TracebackType | None ) -> None: ... @@ -76,7 +76,7 @@ class TCPServer(BaseServer): allow_reuse_port: bool server_address: _AfInetAddress # type: ignore[assignment] def __init__( - self: Self, + self, server_address: _AfInetAddress, RequestHandlerClass: Callable[[Any, _RetAddress, Self], BaseRequestHandler], bind_and_activate: bool = True, @@ -91,7 +91,7 @@ if sys.platform != "win32": class UnixStreamServer(BaseServer): server_address: _AfUnixAddress # type: ignore[assignment] def __init__( - self: Self, + self, server_address: _AfUnixAddress, RequestHandlerClass: Callable[[Any, _RetAddress, Self], BaseRequestHandler], bind_and_activate: bool = True, @@ -100,7 +100,7 @@ if sys.platform != "win32": class UnixDatagramServer(BaseServer): server_address: _AfUnixAddress # type: ignore[assignment] def __init__( - self: Self, + self, server_address: _AfUnixAddress, RequestHandlerClass: Callable[[Any, _RetAddress, Self], BaseRequestHandler], bind_and_activate: bool = True, diff --git a/stdlib/sqlite3/dbapi2.pyi b/stdlib/sqlite3/dbapi2.pyi index 5111a2de9061..26188445547e 100644 --- a/stdlib/sqlite3/dbapi2.pyi +++ b/stdlib/sqlite3/dbapi2.pyi @@ -1,11 +1,11 @@ import sqlite3 import sys -from _typeshed import Incomplete, ReadableBuffer, Self, StrOrBytesPath, SupportsLenAndGetItem, Unused +from _typeshed import Incomplete, ReadableBuffer, StrOrBytesPath, SupportsLenAndGetItem, Unused from collections.abc import Callable, Generator, Iterable, Iterator, Mapping from datetime import date, datetime, time from types import TracebackType from typing import Any, Protocol, TypeVar, overload -from typing_extensions import Literal, SupportsIndex, TypeAlias, final +from typing_extensions import Literal, Self, SupportsIndex, TypeAlias, final _T = TypeVar("_T") _CursorT = TypeVar("_CursorT", bound=Cursor) @@ -358,7 +358,7 @@ class Connection: def deserialize(self, __data: ReadableBuffer, *, name: str = "main") -> None: ... def __call__(self, __sql: str) -> _Statement: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__( self, __type: type[BaseException] | None, __value: BaseException | None, __traceback: TracebackType | None ) -> Literal[False]: ... @@ -377,8 +377,8 @@ class Cursor(Iterator[Any]): def rowcount(self) -> int: ... def __init__(self, __cursor: Connection) -> None: ... def close(self) -> None: ... - def execute(self: Self, __sql: str, __parameters: _Parameters = ...) -> Self: ... - def executemany(self: Self, __sql: str, __seq_of_parameters: Iterable[_Parameters]) -> Self: ... + def execute(self, __sql: str, __parameters: _Parameters = ...) -> Self: ... + def executemany(self, __sql: str, __seq_of_parameters: Iterable[_Parameters]) -> Self: ... def executescript(self, __sql_script: str) -> Cursor: ... def fetchall(self) -> list[Any]: ... def fetchmany(self, size: int | None = 1) -> list[Any]: ... @@ -387,7 +387,7 @@ class Cursor(Iterator[Any]): def fetchone(self) -> Any: ... def setinputsizes(self, __sizes: Unused) -> None: ... # does nothing def setoutputsize(self, __size: Unused, __column: Unused = None) -> None: ... # does nothing - def __iter__(self: Self) -> Self: ... + def __iter__(self) -> Self: ... def __next__(self) -> Any: ... class DataError(DatabaseError): ... @@ -452,7 +452,7 @@ if sys.version_info >= (3, 11): # whence must be one of os.SEEK_SET, os.SEEK_CUR, os.SEEK_END def seek(self, __offset: int, __origin: int = 0) -> None: ... def __len__(self) -> int: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__(self, __typ: object, __val: object, __tb: object) -> Literal[False]: ... def __getitem__(self, __item: SupportsIndex | slice) -> int: ... def __setitem__(self, __item: SupportsIndex | slice, __value: int) -> None: ... diff --git a/stdlib/sre_constants.pyi b/stdlib/sre_constants.pyi index fe25eaf9728e..d522372c438c 100644 --- a/stdlib/sre_constants.pyi +++ b/stdlib/sre_constants.pyi @@ -1,6 +1,6 @@ import sys -from _typeshed import Self from typing import Any +from typing_extensions import Self MAXGROUPS: int @@ -16,7 +16,7 @@ class error(Exception): class _NamedIntConstant(int): name: Any - def __new__(cls: type[Self], value: int, name: str) -> Self: ... + def __new__(cls, value: int, name: str) -> Self: ... MAXREPEAT: _NamedIntConstant OPCODES: list[_NamedIntConstant] diff --git a/stdlib/ssl.pyi b/stdlib/ssl.pyi index 73df70c00d3c..bbf8a4c6d65a 100644 --- a/stdlib/ssl.pyi +++ b/stdlib/ssl.pyi @@ -1,10 +1,10 @@ import enum import socket import sys -from _typeshed import ReadableBuffer, Self, StrOrBytesPath, WriteableBuffer +from _typeshed import ReadableBuffer, StrOrBytesPath, WriteableBuffer from collections.abc import Callable, Iterable from typing import Any, NamedTuple, overload -from typing_extensions import Literal, TypeAlias, TypedDict, final +from typing_extensions import Literal, Self, TypeAlias, TypedDict, final _PCTRTT: TypeAlias = tuple[tuple[str, str], ...] _PCTRTTT: TypeAlias = tuple[_PCTRTT, ...] @@ -297,9 +297,9 @@ class _ASN1Object(NamedTuple): longname: str oid: str @classmethod - def fromnid(cls: type[Self], nid: int) -> Self: ... + def fromnid(cls, nid: int) -> Self: ... @classmethod - def fromname(cls: type[Self], name: str) -> Self: ... + def fromname(cls, name: str) -> Self: ... class Purpose(_ASN1Object, enum.Enum): SERVER_AUTH: _ASN1Object @@ -383,9 +383,9 @@ class SSLContext: if sys.version_info >= (3, 10): # Using the default (None) for the `protocol` parameter is deprecated, # but there isn't a good way of marking that in the stub unless/until PEP 702 is accepted - def __new__(cls: type[Self], protocol: int | None = None, *args: Any, **kwargs: Any) -> Self: ... + def __new__(cls, protocol: int | None = None, *args: Any, **kwargs: Any) -> Self: ... else: - def __new__(cls: type[Self], protocol: int = ..., *args: Any, **kwargs: Any) -> Self: ... + def __new__(cls, protocol: int = ..., *args: Any, **kwargs: Any) -> Self: ... def cert_store_stats(self) -> dict[str, int]: ... def load_cert_chain( diff --git a/stdlib/statistics.pyi b/stdlib/statistics.pyi index 4ef950b9b4de..1358b1f90d7d 100644 --- a/stdlib/statistics.pyi +++ b/stdlib/statistics.pyi @@ -1,10 +1,10 @@ import sys -from _typeshed import Self, SupportsRichComparisonT +from _typeshed import SupportsRichComparisonT from collections.abc import Hashable, Iterable, Sequence from decimal import Decimal from fractions import Fraction from typing import Any, NamedTuple, SupportsFloat, TypeVar -from typing_extensions import Literal, TypeAlias +from typing_extensions import Literal, Self, TypeAlias __all__ = [ "StatisticsError", @@ -93,7 +93,7 @@ if sys.version_info >= (3, 8): @property def variance(self) -> float: ... @classmethod - def from_samples(cls: type[Self], data: Iterable[SupportsFloat]) -> Self: ... + def from_samples(cls, data: Iterable[SupportsFloat]) -> Self: ... def samples(self, n: int, *, seed: Any | None = None) -> list[float]: ... def pdf(self, x: float) -> float: ... def cdf(self, x: float) -> float: ... diff --git a/stdlib/subprocess.pyi b/stdlib/subprocess.pyi index 63a6836286b3..3940fad7b915 100644 --- a/stdlib/subprocess.pyi +++ b/stdlib/subprocess.pyi @@ -1,9 +1,9 @@ import sys -from _typeshed import ReadableBuffer, Self, StrOrBytesPath +from _typeshed import ReadableBuffer, StrOrBytesPath from collections.abc import Callable, Collection, Iterable, Mapping, Sequence from types import TracebackType from typing import IO, Any, AnyStr, Generic, TypeVar, overload -from typing_extensions import Literal, TypeAlias +from typing_extensions import Literal, Self, TypeAlias if sys.version_info >= (3, 9): from types import GenericAlias @@ -2560,7 +2560,7 @@ class Popen(Generic[AnyStr]): def send_signal(self, sig: int) -> None: ... def terminate(self) -> None: ... def kill(self) -> None: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__( self, exc_type: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None ) -> None: ... diff --git a/stdlib/sunau.pyi b/stdlib/sunau.pyi index 7702443b0c1c..6109b368c01a 100644 --- a/stdlib/sunau.pyi +++ b/stdlib/sunau.pyi @@ -1,7 +1,7 @@ import sys -from _typeshed import Self, Unused +from _typeshed import Unused from typing import IO, Any, NamedTuple, NoReturn, overload -from typing_extensions import Literal, TypeAlias +from typing_extensions import Literal, Self, TypeAlias _File: TypeAlias = str | IO[bytes] @@ -32,7 +32,7 @@ class _sunau_params(NamedTuple): class Au_read: def __init__(self, f: _File) -> None: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__(self, *args: Unused) -> None: ... def getfp(self) -> IO[bytes] | None: ... def rewind(self) -> None: ... @@ -52,7 +52,7 @@ class Au_read: class Au_write: def __init__(self, f: _File) -> None: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__(self, *args: Unused) -> None: ... def setnchannels(self, nchannels: int) -> None: ... def getnchannels(self) -> int: ... diff --git a/stdlib/tarfile.pyi b/stdlib/tarfile.pyi index 0aca7956a580..5cf1d55cac63 100644 --- a/stdlib/tarfile.pyi +++ b/stdlib/tarfile.pyi @@ -1,13 +1,13 @@ import bz2 import io import sys -from _typeshed import Self, StrOrBytesPath, StrPath -from builtins import list as _list, type as Type # aliases to avoid name clashes with fields named "type" or "list" +from _typeshed import StrOrBytesPath, StrPath +from builtins import list as _list # aliases to avoid name clashes with fields named "type" or "list" from collections.abc import Callable, Iterable, Iterator, Mapping from gzip import _ReadableFileobj as _GzipReadableFileobj, _WritableFileobj as _GzipWritableFileobj from types import TracebackType from typing import IO, ClassVar, Protocol, overload -from typing_extensions import Literal +from typing_extensions import Literal, Self __all__ = [ "TarFile", @@ -141,14 +141,14 @@ class TarFile: errorlevel: int | None = None, copybufsize: int | None = None, # undocumented ) -> None: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__( self, type: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None ) -> None: ... def __iter__(self) -> Iterator[TarInfo]: ... @classmethod def open( - cls: type[Self], + cls, name: StrOrBytesPath | None = None, mode: str = "r", fileobj: IO[bytes] | None = None, # depends on mode @@ -166,7 +166,7 @@ class TarFile: ) -> Self: ... @classmethod def taropen( - cls: type[Self], + cls, name: StrOrBytesPath | None, mode: Literal["r", "a", "w", "x"] = "r", fileobj: _Fileobj | None = None, @@ -184,7 +184,7 @@ class TarFile: @overload @classmethod def gzopen( - cls: type[Self], + cls, name: StrOrBytesPath | None, mode: Literal["r"] = "r", fileobj: _GzipReadableFileobj | None = None, @@ -202,7 +202,7 @@ class TarFile: @overload @classmethod def gzopen( - cls: type[Self], + cls, name: StrOrBytesPath | None, mode: Literal["w", "x"], fileobj: _GzipWritableFileobj | None = None, @@ -220,7 +220,7 @@ class TarFile: @overload @classmethod def bz2open( - cls: type[Self], + cls, name: StrOrBytesPath | None, mode: Literal["w", "x"], fileobj: _Bz2WritableFileobj | None = None, @@ -238,7 +238,7 @@ class TarFile: @overload @classmethod def bz2open( - cls: type[Self], + cls, name: StrOrBytesPath | None, mode: Literal["r"] = "r", fileobj: _Bz2ReadableFileobj | None = None, @@ -255,7 +255,7 @@ class TarFile: ) -> Self: ... @classmethod def xzopen( - cls: type[Self], + cls, name: StrOrBytesPath | None, mode: Literal["r", "w", "x"] = "r", fileobj: IO[bytes] | None = None, @@ -346,9 +346,9 @@ class TarInfo: pax_headers: Mapping[str, str] def __init__(self, name: str = "") -> None: ... @classmethod - def frombuf(cls: Type[Self], buf: bytes | bytearray, encoding: str, errors: str) -> Self: ... + def frombuf(cls, buf: bytes | bytearray, encoding: str, errors: str) -> Self: ... @classmethod - def fromtarfile(cls: Type[Self], tarfile: TarFile) -> Self: ... + def fromtarfile(cls, tarfile: TarFile) -> Self: ... @property def linkpath(self) -> str: ... @linkpath.setter diff --git a/stdlib/telnetlib.pyi b/stdlib/telnetlib.pyi index bcf9ef3693b2..10f6e4930f75 100644 --- a/stdlib/telnetlib.pyi +++ b/stdlib/telnetlib.pyi @@ -1,9 +1,9 @@ import socket -from _typeshed import Self from collections.abc import Callable, Sequence from re import Match, Pattern from types import TracebackType from typing import Any +from typing_extensions import Self __all__ = ["Telnet"] @@ -115,7 +115,7 @@ class Telnet: def expect( self, list: Sequence[Pattern[bytes] | bytes], timeout: float | None = None ) -> tuple[int, Match[bytes] | None, bytes]: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__( self, type: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None ) -> None: ... diff --git a/stdlib/tempfile.pyi b/stdlib/tempfile.pyi index 9dc23be2557f..dbff6d632d02 100644 --- a/stdlib/tempfile.pyi +++ b/stdlib/tempfile.pyi @@ -1,10 +1,10 @@ import io import sys -from _typeshed import BytesPath, GenericPath, Self, StrPath, WriteableBuffer +from _typeshed import BytesPath, GenericPath, StrPath, WriteableBuffer from collections.abc import Iterable, Iterator from types import TracebackType from typing import IO, Any, AnyStr, Generic, overload -from typing_extensions import Literal, TypeAlias +from typing_extensions import Literal, Self, TypeAlias if sys.version_info >= (3, 9): from types import GenericAlias @@ -186,7 +186,7 @@ class _TemporaryFileWrapper(Generic[AnyStr], IO[AnyStr]): name: str delete: bool def __init__(self, file: IO[AnyStr], name: str, delete: bool = True) -> None: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__(self, exc: type[BaseException] | None, value: BaseException | None, tb: TracebackType | None) -> None: ... def __getattr__(self, name: str) -> Any: ... def close(self) -> None: ... @@ -369,7 +369,7 @@ class SpooledTemporaryFile(IO[AnyStr], _SpooledTemporaryFileBase): ) -> None: ... def rollover(self) -> None: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__(self, exc: type[BaseException] | None, value: BaseException | None, tb: TracebackType | None) -> None: ... # These methods are copied from the abstract methods of IO, because # SpooledTemporaryFile implements IO. diff --git a/stdlib/traceback.pyi b/stdlib/traceback.pyi index cdda50c0a1b3..4483a8c2a1b0 100644 --- a/stdlib/traceback.pyi +++ b/stdlib/traceback.pyi @@ -1,9 +1,9 @@ import sys -from _typeshed import Self, SupportsWrite +from _typeshed import SupportsWrite from collections.abc import Generator, Iterable, Iterator, Mapping from types import FrameType, TracebackType from typing import Any, overload -from typing_extensions import Literal, TypeAlias +from typing_extensions import Literal, Self, TypeAlias __all__ = [ "extract_stack", @@ -129,7 +129,7 @@ class TracebackException: ) -> None: ... @classmethod def from_exception( - cls: type[Self], + cls, exc: BaseException, *, limit: int | None = ..., @@ -154,7 +154,7 @@ class TracebackException: ) -> None: ... @classmethod def from_exception( - cls: type[Self], + cls, exc: BaseException, *, limit: int | None = ..., @@ -176,7 +176,7 @@ class TracebackException: ) -> None: ... @classmethod def from_exception( - cls: type[Self], exc: BaseException, *, limit: int | None = ..., lookup_lines: bool = ..., capture_locals: bool = ... + cls, exc: BaseException, *, limit: int | None = ..., lookup_lines: bool = ..., capture_locals: bool = ... ) -> Self: ... def __eq__(self, other: object) -> bool: ... diff --git a/stdlib/turtle.pyi b/stdlib/turtle.pyi index 2187d13b1a13..8017c8290fb9 100644 --- a/stdlib/turtle.pyi +++ b/stdlib/turtle.pyi @@ -1,8 +1,7 @@ -from _typeshed import Self from collections.abc import Callable, Sequence from tkinter import Canvas, Frame, Misc, PhotoImage, Scrollbar from typing import Any, ClassVar, overload -from typing_extensions import TypeAlias +from typing_extensions import Self, TypeAlias __all__ = [ "ScrolledCanvas", @@ -143,7 +142,7 @@ _Speed: TypeAlias = str | float _PolygonCoords: TypeAlias = Sequence[tuple[float, float]] class Vec2D(tuple[float, float]): - def __new__(cls: type[Self], x: float, y: float) -> Self: ... + def __new__(cls, x: float, y: float) -> Self: ... def __add__(self, other: tuple[float, float]) -> Vec2D: ... # type: ignore[override] @overload # type: ignore[override] def __mul__(self, other: Vec2D) -> float: ... @@ -366,7 +365,7 @@ class RawTurtle(TPen, TNavigator): def setundobuffer(self, size: int | None) -> None: ... def undobufferentries(self) -> int: ... def clear(self) -> None: ... - def clone(self: Self) -> Self: ... + def clone(self) -> Self: ... @overload def shape(self, name: None = None) -> str: ... @overload @@ -411,7 +410,7 @@ class RawTurtle(TPen, TNavigator): def end_poly(self) -> None: ... def get_poly(self) -> _PolygonCoords | None: ... def getscreen(self) -> TurtleScreen: ... - def getturtle(self: Self) -> Self: ... + def getturtle(self) -> Self: ... getpen = getturtle def onclick(self, fun: Callable[[float, float], object], btn: int = 1, add: bool | None = None) -> None: ... def onrelease(self, fun: Callable[[float, float], object], btn: int = 1, add: bool | None = None) -> None: ... diff --git a/stdlib/typing.pyi b/stdlib/typing.pyi index 408c277cfa2e..d06b081d3ddc 100644 --- a/stdlib/typing.pyi +++ b/stdlib/typing.pyi @@ -1,4 +1,3 @@ -import _typeshed import collections # Needed by aliases like DefaultDict, see mypy issue 2986 import sys import typing_extensions @@ -502,7 +501,7 @@ class MutableSequence(Sequence[_T], Generic[_T]): def reverse(self) -> None: ... def pop(self, index: int = -1) -> _T: ... def remove(self, value: _T) -> None: ... - def __iadd__(self: _typeshed.Self, values: Iterable[_T]) -> _typeshed.Self: ... + def __iadd__(self, values: Iterable[_T]) -> typing_extensions.Self: ... class AbstractSet(Collection[_T_co], Generic[_T_co]): @abstractmethod @@ -528,10 +527,10 @@ class MutableSet(AbstractSet[_T], Generic[_T]): def clear(self) -> None: ... def pop(self) -> _T: ... def remove(self, value: _T) -> None: ... - def __ior__(self: _typeshed.Self, it: AbstractSet[_T]) -> _typeshed.Self: ... # type: ignore[override,misc] - def __iand__(self: _typeshed.Self, it: AbstractSet[Any]) -> _typeshed.Self: ... - def __ixor__(self: _typeshed.Self, it: AbstractSet[_T]) -> _typeshed.Self: ... # type: ignore[override,misc] - def __isub__(self: _typeshed.Self, it: AbstractSet[Any]) -> _typeshed.Self: ... + def __ior__(self, it: AbstractSet[_T]) -> typing_extensions.Self: ... # type: ignore[override,misc] + def __iand__(self, it: AbstractSet[Any]) -> typing_extensions.Self: ... + def __ixor__(self, it: AbstractSet[_T]) -> typing_extensions.Self: ... # type: ignore[override,misc] + def __isub__(self, it: AbstractSet[Any]) -> typing_extensions.Self: ... class MappingView(Sized): def __init__(self, mapping: Mapping[Any, Any]) -> None: ... # undocumented @@ -792,7 +791,7 @@ class NamedTuple(tuple[Any, ...]): else: def _asdict(self) -> collections.OrderedDict[str, Any]: ... - def _replace(self: _typeshed.Self, **kwargs: Any) -> _typeshed.Self: ... + def _replace(self, **kwargs: Any) -> typing_extensions.Self: ... # Internal mypy fallback type for all typed dicts (does not exist at runtime) # N.B. Keep this mostly in sync with typing_extensions._TypedDict/mypy_extensions._TypedDict @@ -802,7 +801,7 @@ class _TypedDict(Mapping[str, object], metaclass=ABCMeta): if sys.version_info >= (3, 9): __required_keys__: ClassVar[frozenset[str]] __optional_keys__: ClassVar[frozenset[str]] - def copy(self: _typeshed.Self) -> _typeshed.Self: ... + def copy(self) -> typing_extensions.Self: ... # Using Never so that only calls using mypy plugin hook that specialize the signature # can go through. def setdefault(self, k: _Never, default: object) -> object: ... @@ -814,8 +813,8 @@ class _TypedDict(Mapping[str, object], metaclass=ABCMeta): def keys(self) -> dict_keys[str, object]: ... def values(self) -> dict_values[str, object]: ... if sys.version_info >= (3, 9): - def __or__(self: _typeshed.Self, __value: _typeshed.Self) -> _typeshed.Self: ... - def __ior__(self: _typeshed.Self, __value: _typeshed.Self) -> _typeshed.Self: ... + def __or__(self, __value: typing_extensions.Self) -> typing_extensions.Self: ... + def __ior__(self, __value: typing_extensions.Self) -> typing_extensions.Self: ... @_final class ForwardRef: diff --git a/stdlib/typing_extensions.pyi b/stdlib/typing_extensions.pyi index 8ba91e539bec..bf3892d5709e 100644 --- a/stdlib/typing_extensions.pyi +++ b/stdlib/typing_extensions.pyi @@ -1,4 +1,3 @@ -import _typeshed import abc import collections import sys @@ -129,7 +128,7 @@ class _TypedDict(Mapping[str, object], metaclass=abc.ABCMeta): __required_keys__: ClassVar[frozenset[str]] __optional_keys__: ClassVar[frozenset[str]] __total__: ClassVar[bool] - def copy(self: _typeshed.Self) -> _typeshed.Self: ... + def copy(self) -> Self: ... # Using Never so that only calls using mypy plugin hook that specialize the signature # can go through. def setdefault(self, k: Never, default: object) -> object: ... @@ -141,8 +140,8 @@ class _TypedDict(Mapping[str, object], metaclass=abc.ABCMeta): def values(self) -> dict_values[str, object]: ... def __delitem__(self, k: Never) -> None: ... if sys.version_info >= (3, 9): - def __or__(self: _typeshed.Self, __value: _typeshed.Self) -> _typeshed.Self: ... - def __ior__(self: _typeshed.Self, __value: _typeshed.Self) -> _typeshed.Self: ... + def __or__(self, __value: Self) -> Self: ... + def __ior__(self, __value: Self) -> Self: ... # TypedDict is a (non-subscriptable) special form. TypedDict: object @@ -244,13 +243,13 @@ else: @overload def __init__(self, typename: str, fields: None = None, **kwargs: Any) -> None: ... @classmethod - def _make(cls: type[_typeshed.Self], iterable: Iterable[Any]) -> _typeshed.Self: ... + def _make(cls, iterable: Iterable[Any]) -> Self: ... if sys.version_info >= (3, 8): def _asdict(self) -> dict[str, Any]: ... else: def _asdict(self) -> collections.OrderedDict[str, Any]: ... - def _replace(self: _typeshed.Self, **kwargs: Any) -> _typeshed.Self: ... + def _replace(self, **kwargs: Any) -> Self: ... # New things in 3.xx # The `default` parameter was added to TypeVar, ParamSpec, and TypeVarTuple (PEP 696) diff --git a/stdlib/unittest/case.pyi b/stdlib/unittest/case.pyi index 630267a7ce07..8f8cf43385a8 100644 --- a/stdlib/unittest/case.pyi +++ b/stdlib/unittest/case.pyi @@ -1,13 +1,13 @@ import logging import sys import unittest.result -from _typeshed import Self, SupportsDunderGE, SupportsDunderGT, SupportsDunderLE, SupportsDunderLT, SupportsRSub, SupportsSub +from _typeshed import SupportsDunderGE, SupportsDunderGT, SupportsDunderLE, SupportsDunderLT, SupportsRSub, SupportsSub from collections.abc import Callable, Container, Iterable, Mapping, Sequence, Set as AbstractSet from contextlib import AbstractContextManager from re import Pattern from types import TracebackType from typing import Any, AnyStr, ClassVar, Generic, NamedTuple, NoReturn, Protocol, SupportsAbs, SupportsRound, TypeVar, overload -from typing_extensions import ParamSpec, TypeAlias +from typing_extensions import ParamSpec, Self, TypeAlias from warnings import WarningMessage if sys.version_info >= (3, 9): @@ -304,7 +304,7 @@ class FunctionTestCase(TestCase): class _AssertRaisesContext(Generic[_E]): exception: _E - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__( self, exc_type: type[BaseException] | None, exc_value: BaseException | None, tb: TracebackType | None ) -> bool: ... @@ -316,7 +316,7 @@ class _AssertWarnsContext: filename: str lineno: int warnings: list[WarningMessage] - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__( self, exc_type: type[BaseException] | None, exc_value: BaseException | None, tb: TracebackType | None ) -> None: ... diff --git a/stdlib/unittest/mock.pyi b/stdlib/unittest/mock.pyi index 54c79fd433d2..3b1989edca9e 100644 --- a/stdlib/unittest/mock.pyi +++ b/stdlib/unittest/mock.pyi @@ -1,10 +1,9 @@ import sys -from _typeshed import Self from collections.abc import Awaitable, Callable, Coroutine, Iterable, Mapping, Sequence from contextlib import _GeneratorContextManager from types import TracebackType from typing import Any, Generic, TypeVar, overload -from typing_extensions import Literal, TypeAlias +from typing_extensions import Literal, Self, TypeAlias _T = TypeVar("_T") _TT = TypeVar("_TT", bound=type[Any]) @@ -68,12 +67,7 @@ _CallValue: TypeAlias = str | tuple[Any, ...] | Mapping[str, Any] | _ArgsKwargs class _Call(tuple[Any, ...]): def __new__( - cls: type[Self], - value: _CallValue = ..., - name: str | None = "", - parent: Any | None = None, - two: bool = False, - from_kall: bool = True, + cls, value: _CallValue = ..., name: str | None = "", parent: Any | None = None, two: bool = False, from_kall: bool = True ) -> Self: ... name: Any parent: Any @@ -108,7 +102,7 @@ class Base: def __init__(self, *args: Any, **kwargs: Any) -> None: ... class NonCallableMock(Base, Any): - def __new__(__cls: type[Self], *args: Any, **kw: Any) -> Self: ... + def __new__(__cls, *args: Any, **kw: Any) -> Self: ... def __init__( self, spec: list[str] | object | type[object] | None = None, @@ -437,9 +431,9 @@ def mock_open(mock: Any | None = None, read_data: Any = "") -> Any: ... class PropertyMock(Mock): if sys.version_info >= (3, 8): - def __get__(self: Self, obj: _T, obj_type: type[_T] | None = None) -> Self: ... + def __get__(self, obj: _T, obj_type: type[_T] | None = None) -> Self: ... else: - def __get__(self: Self, obj: _T, obj_type: type[_T] | None) -> Self: ... + def __get__(self, obj: _T, obj_type: type[_T] | None) -> Self: ... def __set__(self, obj: Any, value: Any) -> None: ... diff --git a/stdlib/urllib/response.pyi b/stdlib/urllib/response.pyi index 4db1b5649c7a..61ba687076b2 100644 --- a/stdlib/urllib/response.pyi +++ b/stdlib/urllib/response.pyi @@ -1,20 +1,21 @@ import sys -from _typeshed import ReadableBuffer, Self +from _typeshed import ReadableBuffer from collections.abc import Callable, Iterable from email.message import Message from types import TracebackType from typing import IO, Any, BinaryIO +from typing_extensions import Self __all__ = ["addbase", "addclosehook", "addinfo", "addinfourl"] class addbase(BinaryIO): fp: IO[bytes] def __init__(self, fp: IO[bytes]) -> None: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__( self, type: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None ) -> None: ... - def __iter__(self: Self) -> Self: ... + def __iter__(self) -> Self: ... def __next__(self) -> bytes: ... def close(self) -> None: ... # These methods don't actually exist, but the class inherits at runtime from diff --git a/stdlib/wave.pyi b/stdlib/wave.pyi index 3817ae09307f..0d004d6b2d8a 100644 --- a/stdlib/wave.pyi +++ b/stdlib/wave.pyi @@ -1,7 +1,7 @@ import sys -from _typeshed import ReadableBuffer, Self, Unused +from _typeshed import ReadableBuffer, Unused from typing import IO, Any, BinaryIO, NamedTuple, NoReturn, overload -from typing_extensions import Literal, TypeAlias +from typing_extensions import Literal, Self, TypeAlias if sys.version_info >= (3, 9): __all__ = ["open", "Error", "Wave_read", "Wave_write"] @@ -24,7 +24,7 @@ class _wave_params(NamedTuple): class Wave_read: def __init__(self, f: _File) -> None: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__(self, *args: Unused) -> None: ... def getfp(self) -> BinaryIO | None: ... def rewind(self) -> None: ... @@ -44,7 +44,7 @@ class Wave_read: class Wave_write: def __init__(self, f: _File) -> None: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__(self, *args: Unused) -> None: ... def setnchannels(self, nchannels: int) -> None: ... def getnchannels(self) -> int: ... diff --git a/stdlib/weakref.pyi b/stdlib/weakref.pyi index a0f35b4f51eb..1e0aac814dfb 100644 --- a/stdlib/weakref.pyi +++ b/stdlib/weakref.pyi @@ -1,5 +1,5 @@ import sys -from _typeshed import Self, SupportsKeysAndGetItem +from _typeshed import SupportsKeysAndGetItem from _weakref import ( CallableProxyType as CallableProxyType, ProxyType as ProxyType, @@ -12,7 +12,7 @@ from _weakref import ( from _weakrefset import WeakSet as WeakSet from collections.abc import Callable, Iterable, Iterator, Mapping, MutableMapping from typing import Any, Generic, TypeVar, overload -from typing_extensions import ParamSpec +from typing_extensions import ParamSpec, Self __all__ = [ "ref", @@ -41,7 +41,7 @@ _P = ParamSpec("_P") ProxyTypes: tuple[type[Any], ...] class WeakMethod(ref[_CallableT], Generic[_CallableT]): - def __new__(cls: type[Self], meth: _CallableT, callback: Callable[[_CallableT], object] | None = None) -> Self: ... + def __new__(cls, meth: _CallableT, callback: Callable[[_CallableT], object] | None = None) -> Self: ... def __call__(self) -> _CallableT | None: ... def __eq__(self, other: object) -> bool: ... def __ne__(self, other: object) -> bool: ... @@ -63,7 +63,7 @@ class WeakValueDictionary(MutableMapping[_KT, _VT]): def __iter__(self) -> Iterator[_KT]: ... def copy(self) -> WeakValueDictionary[_KT, _VT]: ... __copy__ = copy - def __deepcopy__(self: Self, memo: Any) -> Self: ... + def __deepcopy__(self, memo: Any) -> Self: ... # These are incompatible with Mapping def keys(self) -> Iterator[_KT]: ... # type: ignore[override] def values(self) -> Iterator[_VT]: ... # type: ignore[override] @@ -80,14 +80,14 @@ class WeakValueDictionary(MutableMapping[_KT, _VT]): def __ror__(self, other: Mapping[_T1, _T2]) -> WeakValueDictionary[_KT | _T1, _VT | _T2]: ... # WeakValueDictionary.__ior__ should be kept roughly in line with MutableMapping.update() @overload # type: ignore[misc] - def __ior__(self: Self, other: SupportsKeysAndGetItem[_KT, _VT]) -> Self: ... + def __ior__(self, other: SupportsKeysAndGetItem[_KT, _VT]) -> Self: ... @overload - def __ior__(self: Self, other: Iterable[tuple[_KT, _VT]]) -> Self: ... + def __ior__(self, other: Iterable[tuple[_KT, _VT]]) -> Self: ... class KeyedRef(ref[_T], Generic[_KT, _T]): key: _KT # This __new__ method uses a non-standard name for the "cls" parameter - def __new__(type: type[Self], ob: _T, callback: Callable[[_T], Any], key: _KT) -> Self: ... + def __new__(type, ob: _T, callback: Callable[[_T], Any], key: _KT) -> Self: ... def __init__(self, ob: _T, callback: Callable[[_T], Any], key: _KT) -> None: ... class WeakKeyDictionary(MutableMapping[_KT, _VT]): @@ -103,7 +103,7 @@ class WeakKeyDictionary(MutableMapping[_KT, _VT]): def __iter__(self) -> Iterator[_KT]: ... def copy(self) -> WeakKeyDictionary[_KT, _VT]: ... __copy__ = copy - def __deepcopy__(self: Self, memo: Any) -> Self: ... + def __deepcopy__(self, memo: Any) -> Self: ... # These are incompatible with Mapping def keys(self) -> Iterator[_KT]: ... # type: ignore[override] def values(self) -> Iterator[_VT]: ... # type: ignore[override] @@ -123,9 +123,9 @@ class WeakKeyDictionary(MutableMapping[_KT, _VT]): def __ror__(self, other: Mapping[_T1, _T2]) -> WeakKeyDictionary[_KT | _T1, _VT | _T2]: ... # WeakKeyDictionary.__ior__ should be kept roughly in line with MutableMapping.update() @overload # type: ignore[misc] - def __ior__(self: Self, other: SupportsKeysAndGetItem[_KT, _VT]) -> Self: ... + def __ior__(self, other: SupportsKeysAndGetItem[_KT, _VT]) -> Self: ... @overload - def __ior__(self: Self, other: Iterable[tuple[_KT, _VT]]) -> Self: ... + def __ior__(self, other: Iterable[tuple[_KT, _VT]]) -> Self: ... class finalize: # TODO: This is a good candidate for to be a `Generic[_P, _T]` class def __init__(self, __obj: object, __func: Callable[_P, Any], *args: _P.args, **kwargs: _P.kwargs) -> None: ... diff --git a/stdlib/winreg.pyi b/stdlib/winreg.pyi index 6377492babc7..5b2d09a3bebc 100644 --- a/stdlib/winreg.pyi +++ b/stdlib/winreg.pyi @@ -1,8 +1,7 @@ import sys -from _typeshed import Self from types import TracebackType from typing import Any -from typing_extensions import Literal, TypeAlias, final +from typing_extensions import Literal, Self, TypeAlias, final if sys.platform == "win32": _KeyType: TypeAlias = HKEYType | int @@ -93,7 +92,7 @@ if sys.platform == "win32": class HKEYType: def __bool__(self) -> bool: ... def __int__(self) -> int: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__( self, exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: TracebackType | None ) -> bool | None: ... diff --git a/stdlib/xml/dom/minidom.pyi b/stdlib/xml/dom/minidom.pyi index d996f66984f9..7bbffb88c8f7 100644 --- a/stdlib/xml/dom/minidom.pyi +++ b/stdlib/xml/dom/minidom.pyi @@ -1,7 +1,7 @@ import sys import xml.dom -from _typeshed import Incomplete, ReadableBuffer, Self, SupportsRead, SupportsWrite -from typing_extensions import Literal +from _typeshed import Incomplete, ReadableBuffer, SupportsRead, SupportsWrite +from typing_extensions import Literal, Self from xml.dom.xmlbuilder import DocumentLS, DOMImplementationLS from xml.sax.xmlreader import XMLReader @@ -46,7 +46,7 @@ class Node(xml.dom.Node): def setUserData(self, key, data, handler): ... childNodes: Incomplete def unlink(self) -> None: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__(self, et, ev, tb) -> None: ... class DocumentFragment(Node): @@ -269,7 +269,7 @@ class DOMImplementation(DOMImplementationLS): def hasFeature(self, feature: str, version: str | None) -> bool: ... def createDocument(self, namespaceURI: str | None, qualifiedName: str | None, doctype: DocumentType | None) -> Document: ... def createDocumentType(self, qualifiedName: str | None, publicId: str, systemId: str) -> DocumentType: ... - def getInterface(self: Self, feature: str) -> Self | None: ... + def getInterface(self, feature: str) -> Self | None: ... class ElementInfo: tagName: Incomplete diff --git a/stdlib/xmlrpc/client.pyi b/stdlib/xmlrpc/client.pyi index 86d21abd7725..7bf701ae716d 100644 --- a/stdlib/xmlrpc/client.pyi +++ b/stdlib/xmlrpc/client.pyi @@ -2,13 +2,13 @@ import gzip import http.client import sys import time -from _typeshed import ReadableBuffer, Self, SupportsRead, SupportsWrite, _BufferWithLen +from _typeshed import ReadableBuffer, SupportsRead, SupportsWrite, _BufferWithLen from collections.abc import Callable, Iterable, Mapping from datetime import datetime from io import BytesIO from types import TracebackType from typing import Any, Protocol, overload -from typing_extensions import Literal, TypeAlias +from typing_extensions import Literal, Self, TypeAlias class _SupportsTimeTuple(Protocol): def timetuple(self) -> time.struct_time: ... @@ -312,7 +312,7 @@ class ServerProxy: def __call__(self, attr: Literal["transport"]) -> Transport: ... @overload def __call__(self, attr: str) -> Callable[[], None] | Transport: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__( self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None ) -> None: ... diff --git a/stdlib/zipfile.pyi b/stdlib/zipfile.pyi index 0cb6138dfddd..b969d0cf9e6a 100644 --- a/stdlib/zipfile.pyi +++ b/stdlib/zipfile.pyi @@ -1,11 +1,11 @@ import io import sys -from _typeshed import Self, StrOrBytesPath, StrPath, _BufferWithLen +from _typeshed import StrOrBytesPath, StrPath, _BufferWithLen from collections.abc import Callable, Iterable, Iterator from os import PathLike from types import TracebackType from typing import IO, Any, Protocol, overload -from typing_extensions import Literal, TypeAlias +from typing_extensions import Literal, Self, TypeAlias __all__ = [ "BadZipFile", @@ -150,7 +150,7 @@ class ZipFile: compresslevel: int | None = None, ) -> None: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__( self, type: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None ) -> None: ... @@ -214,12 +214,10 @@ class ZipInfo: def __init__(self, filename: str = "NoName", date_time: _DateTuple = ...) -> None: ... if sys.version_info >= (3, 8): @classmethod - def from_file( - cls: type[Self], filename: StrPath, arcname: StrPath | None = None, *, strict_timestamps: bool = True - ) -> Self: ... + def from_file(cls, filename: StrPath, arcname: StrPath | None = None, *, strict_timestamps: bool = True) -> Self: ... else: @classmethod - def from_file(cls: type[Self], filename: StrPath, arcname: StrPath | None = None) -> Self: ... + def from_file(cls, filename: StrPath, arcname: StrPath | None = None) -> Self: ... def is_dir(self) -> bool: ... def FileHeader(self, zip64: bool | None = None) -> bytes: ... diff --git a/stdlib/zoneinfo/__init__.pyi b/stdlib/zoneinfo/__init__.pyi index 0bdf853f4069..fe994be3e8ff 100644 --- a/stdlib/zoneinfo/__init__.pyi +++ b/stdlib/zoneinfo/__init__.pyi @@ -1,7 +1,8 @@ -from _typeshed import Self, StrPath +from _typeshed import StrPath from collections.abc import Iterable, Sequence from datetime import datetime, timedelta, tzinfo from typing import Any, Protocol +from typing_extensions import Self __all__ = ["ZoneInfo", "reset_tzpath", "available_timezones", "TZPATH", "ZoneInfoNotFoundError", "InvalidTZPathWarning"] @@ -14,9 +15,9 @@ class ZoneInfo(tzinfo): def key(self) -> str: ... def __init__(self, key: str) -> None: ... @classmethod - def no_cache(cls: type[Self], key: str) -> Self: ... + def no_cache(cls, key: str) -> Self: ... @classmethod - def from_file(cls: type[Self], __fobj: _IOBytes, key: str | None = ...) -> Self: ... + def from_file(cls, __fobj: _IOBytes, key: str | None = ...) -> Self: ... @classmethod def clear_cache(cls, *, only_keys: Iterable[str] | None = ...) -> None: ... def tzname(self, __dt: datetime | None) -> str | None: ...