mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-29 07:06:55 +08:00
Improve Self type usage accross stdlib (#7183)
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import sys
|
||||
from _typeshed import Self
|
||||
from concurrent.futures._base import Error, Future as _ConcurrentFuture
|
||||
from typing import Any, Awaitable, Callable, Generator, Iterable, TypeVar
|
||||
|
||||
@@ -16,7 +17,6 @@ if sys.version_info >= (3, 9):
|
||||
from types import GenericAlias
|
||||
|
||||
_T = TypeVar("_T")
|
||||
_S = TypeVar("_S")
|
||||
|
||||
if sys.version_info < (3, 7):
|
||||
class _TracebackLogger:
|
||||
@@ -39,12 +39,12 @@ class Future(Awaitable[_T], Iterable[_T]):
|
||||
def __del__(self) -> None: ...
|
||||
if sys.version_info >= (3, 7):
|
||||
def get_loop(self) -> AbstractEventLoop: ...
|
||||
def _callbacks(self: _S) -> list[tuple[Callable[[_S], Any], Context]]: ...
|
||||
def add_done_callback(self: _S, __fn: Callable[[_S], Any], *, context: Context | None = ...) -> None: ...
|
||||
def _callbacks(self: Self) -> list[tuple[Callable[[Self], Any], Context]]: ...
|
||||
def add_done_callback(self: Self, __fn: Callable[[Self], Any], *, context: Context | None = ...) -> None: ...
|
||||
else:
|
||||
@property
|
||||
def _callbacks(self: _S) -> list[Callable[[_S], Any]]: ...
|
||||
def add_done_callback(self: _S, __fn: Callable[[_S], Any]) -> None: ...
|
||||
def _callbacks(self: Self) -> list[Callable[[Self], Any]]: ...
|
||||
def add_done_callback(self: Self, __fn: Callable[[Self], Any]) -> None: ...
|
||||
if sys.version_info >= (3, 9):
|
||||
def cancel(self, msg: Any | None = ...) -> bool: ...
|
||||
else:
|
||||
@@ -54,7 +54,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: _S, __fn: Callable[[_S], Any]) -> int: ...
|
||||
def remove_done_callback(self: Self, __fn: Callable[[Self], Any]) -> int: ...
|
||||
def set_result(self, __result: _T) -> None: ...
|
||||
def set_exception(self, __exception: type | BaseException) -> None: ...
|
||||
def __iter__(self) -> Generator[Any, None, _T]: ...
|
||||
|
||||
@@ -112,8 +112,6 @@ class UserList(MutableSequence[_T]):
|
||||
def sort(self, *, key: Callable[[_T], SupportsRichComparison], reverse: bool = ...) -> None: ...
|
||||
def extend(self, other: Iterable[_T]) -> None: ...
|
||||
|
||||
_UserStringT = TypeVar("_UserStringT", bound=UserString)
|
||||
|
||||
class UserString(Sequence[str]):
|
||||
data: str
|
||||
def __init__(self, seq: object) -> None: ...
|
||||
@@ -129,8 +127,8 @@ class UserString(Sequence[str]):
|
||||
def __len__(self) -> int: ...
|
||||
# It should return a str to implement Sequence correctly, but it doesn't.
|
||||
def __getitem__(self: Self, i: SupportsIndex | slice) -> Self: ... # type: ignore[override]
|
||||
def __iter__(self: _UserStringT) -> Iterator[_UserStringT]: ... # type: ignore[override]
|
||||
def __reversed__(self: _UserStringT) -> Iterator[_UserStringT]: ... # type: ignore[override]
|
||||
def __iter__(self: Self) -> Iterator[Self]: ... # type: ignore[override]
|
||||
def __reversed__(self: Self) -> Iterator[Self]: ... # type: ignore[override]
|
||||
def __add__(self: Self, other: object) -> Self: ...
|
||||
def __mul__(self: Self, n: int) -> Self: ...
|
||||
def __mod__(self: Self, args: Any) -> Self: ...
|
||||
|
||||
Reference in New Issue
Block a user