Use typing_extensions.Self in the stdlib (#9694)

This commit is contained in:
Alex Waygood
2023-02-09 09:12:13 +00:00
committed by GitHub
parent 10086c06a1
commit 9ed39d8796
98 changed files with 627 additions and 654 deletions

View File

@@ -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: ...

View File

@@ -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]: ...

View File

@@ -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: ...

View File

@@ -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: ...

View File

@@ -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: ...

View File

@@ -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

View File

@@ -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: ...

View File

@@ -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: ...

View File

@@ -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 = ...,