mirror of
https://github.com/davidhalter/typeshed.git
synced 2026-01-27 13:22:11 +08:00
Always use _typeshed.Self, where applicable (#6880)
* Always use `_typeshed.Self`, where applicable * Revert changes to `google-cloud-ndb` (ambiguous) * Remove empty line added by script * Revert changes to `stubs/python-dateutil/dateutil/relativedelta.pyi` * Manually add a few more that the script missed * Improve `filelock` annotation Source code here:79ec7b2826/src/filelock/_api.py (L207)* Improve `opentracing/scope` annotation Source code here:3e1d357a34/opentracing/scope.py (L71)* Improve `redis/client` stub Source code here:15f315a496/redis/client.py (L1217)* Improve `redis/lock` annotation Source code here:15f315a496/redis/lock.py (L155)* Improve `requests/models` annotation Source code here:d718e75383/requests/models.py (L653)
This commit is contained in:
@@ -83,15 +83,15 @@ class UserList(MutableSequence[_T]):
|
||||
@overload
|
||||
def __setitem__(self, i: slice, o: Iterable[_T]) -> None: ...
|
||||
def __delitem__(self, i: SupportsIndex | slice) -> None: ...
|
||||
def __add__(self: _S, other: Iterable[_T]) -> _S: ...
|
||||
def __iadd__(self: _S, other: Iterable[_T]) -> _S: ...
|
||||
def __mul__(self: _S, n: int) -> _S: ...
|
||||
def __imul__(self: _S, n: int) -> _S: ...
|
||||
def __add__(self: Self, other: Iterable[_T]) -> Self: ...
|
||||
def __iadd__(self: Self, other: Iterable[_T]) -> Self: ...
|
||||
def __mul__(self: Self, n: int) -> Self: ...
|
||||
def __imul__(self: Self, n: int) -> Self: ...
|
||||
def append(self, item: _T) -> None: ...
|
||||
def insert(self, i: int, item: _T) -> None: ...
|
||||
def pop(self, i: int = ...) -> _T: ...
|
||||
def remove(self, item: _T) -> None: ...
|
||||
def copy(self: _S) -> _S: ...
|
||||
def copy(self: 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 = ..., __stop: SupportsIndex = ...) -> int: ...
|
||||
@@ -118,22 +118,22 @@ class UserString(Sequence[str]):
|
||||
def __contains__(self, char: object) -> bool: ...
|
||||
def __len__(self) -> int: ...
|
||||
# It should return a str to implement Sequence correctly, but it doesn't.
|
||||
def __getitem__(self: _UserStringT, i: SupportsIndex | slice) -> _UserStringT: ... # type: ignore[override]
|
||||
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 __add__(self: _UserStringT, other: object) -> _UserStringT: ...
|
||||
def __mul__(self: _UserStringT, n: int) -> _UserStringT: ...
|
||||
def __mod__(self: _UserStringT, args: Any) -> _UserStringT: ...
|
||||
def capitalize(self: _UserStringT) -> _UserStringT: ...
|
||||
def casefold(self: _UserStringT) -> _UserStringT: ...
|
||||
def center(self: _UserStringT, width: int, *args: Any) -> _UserStringT: ...
|
||||
def __add__(self: Self, other: object) -> Self: ...
|
||||
def __mul__(self: Self, n: int) -> Self: ...
|
||||
def __mod__(self: Self, args: Any) -> Self: ...
|
||||
def capitalize(self: Self) -> Self: ...
|
||||
def casefold(self: Self) -> Self: ...
|
||||
def center(self: Self, width: int, *args: Any) -> Self: ...
|
||||
def count(self, sub: str | UserString, start: int = ..., end: int = ...) -> int: ...
|
||||
if sys.version_info >= (3, 8):
|
||||
def encode(self: UserString, encoding: str | None = ..., errors: str | None = ...) -> bytes: ...
|
||||
else:
|
||||
def encode(self: _UserStringT, encoding: str | None = ..., errors: str | None = ...) -> _UserStringT: ...
|
||||
def encode(self: Self, encoding: str | None = ..., errors: str | None = ...) -> Self: ...
|
||||
def endswith(self, suffix: str | tuple[str, ...], start: int | None = ..., end: int | None = ...) -> bool: ...
|
||||
def expandtabs(self: _UserStringT, tabsize: int = ...) -> _UserStringT: ...
|
||||
def expandtabs(self: Self, tabsize: int = ...) -> Self: ...
|
||||
def find(self, sub: str | UserString, start: int = ..., end: int = ...) -> int: ...
|
||||
def format(self, *args: Any, **kwds: Any) -> str: ...
|
||||
def format_map(self, mapping: Mapping[str, Any]) -> str: ...
|
||||
@@ -152,9 +152,9 @@ class UserString(Sequence[str]):
|
||||
if sys.version_info >= (3, 7):
|
||||
def isascii(self) -> bool: ...
|
||||
def join(self, seq: Iterable[str]) -> str: ...
|
||||
def ljust(self: _UserStringT, width: int, *args: Any) -> _UserStringT: ...
|
||||
def lower(self: _UserStringT) -> _UserStringT: ...
|
||||
def lstrip(self: _UserStringT, chars: str | None = ...) -> _UserStringT: ...
|
||||
def ljust(self: Self, width: int, *args: Any) -> Self: ...
|
||||
def lower(self: Self) -> Self: ...
|
||||
def lstrip(self: Self, chars: str | None = ...) -> Self: ...
|
||||
@staticmethod
|
||||
@overload
|
||||
def maketrans(x: dict[int, _T] | dict[str, _T] | dict[str | int, _T]) -> dict[int, _T]: ...
|
||||
@@ -163,24 +163,24 @@ class UserString(Sequence[str]):
|
||||
def maketrans(x: str, y: str, z: str = ...) -> dict[int, int | None]: ...
|
||||
def partition(self, sep: str) -> tuple[str, str, str]: ...
|
||||
if sys.version_info >= (3, 9):
|
||||
def removeprefix(self: _UserStringT, __prefix: str | UserString) -> _UserStringT: ...
|
||||
def removesuffix(self: _UserStringT, __suffix: str | UserString) -> _UserStringT: ...
|
||||
def replace(self: _UserStringT, old: str | UserString, new: str | UserString, maxsplit: int = ...) -> _UserStringT: ...
|
||||
def removeprefix(self: Self, __prefix: str | UserString) -> Self: ...
|
||||
def removesuffix(self: Self, __suffix: str | UserString) -> Self: ...
|
||||
def replace(self: Self, old: str | UserString, new: str | UserString, maxsplit: int = ...) -> Self: ...
|
||||
def rfind(self, sub: str | UserString, start: int = ..., end: int = ...) -> int: ...
|
||||
def rindex(self, sub: str | UserString, start: int = ..., end: int = ...) -> int: ...
|
||||
def rjust(self: _UserStringT, width: int, *args: Any) -> _UserStringT: ...
|
||||
def rjust(self: Self, width: int, *args: Any) -> Self: ...
|
||||
def rpartition(self, sep: str) -> tuple[str, str, str]: ...
|
||||
def rstrip(self: _UserStringT, chars: str | None = ...) -> _UserStringT: ...
|
||||
def rstrip(self: Self, chars: str | None = ...) -> Self: ...
|
||||
def split(self, sep: str | None = ..., maxsplit: int = ...) -> list[str]: ...
|
||||
def rsplit(self, sep: str | None = ..., maxsplit: int = ...) -> list[str]: ...
|
||||
def splitlines(self, keepends: bool = ...) -> list[str]: ...
|
||||
def startswith(self, prefix: str | tuple[str, ...], start: int | None = ..., end: int | None = ...) -> bool: ...
|
||||
def strip(self: _UserStringT, chars: str | None = ...) -> _UserStringT: ...
|
||||
def swapcase(self: _UserStringT) -> _UserStringT: ...
|
||||
def title(self: _UserStringT) -> _UserStringT: ...
|
||||
def translate(self: _UserStringT, *args: Any) -> _UserStringT: ...
|
||||
def upper(self: _UserStringT) -> _UserStringT: ...
|
||||
def zfill(self: _UserStringT, width: int) -> _UserStringT: ...
|
||||
def strip(self: Self, chars: str | 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: ...
|
||||
|
||||
class deque(MutableSequence[_T], Generic[_T]):
|
||||
@property
|
||||
@@ -188,7 +188,7 @@ class deque(MutableSequence[_T], Generic[_T]):
|
||||
def __init__(self, iterable: Iterable[_T] = ..., maxlen: int | None = ...) -> None: ...
|
||||
def append(self, __x: _T) -> None: ...
|
||||
def appendleft(self, __x: _T) -> None: ...
|
||||
def copy(self: _S) -> _S: ...
|
||||
def copy(self: Self) -> Self: ...
|
||||
def count(self, __x: _T) -> int: ...
|
||||
def extend(self, __iterable: Iterable[_T]) -> None: ...
|
||||
def extendleft(self, __iterable: Iterable[_T]) -> None: ...
|
||||
@@ -198,7 +198,7 @@ class deque(MutableSequence[_T], Generic[_T]):
|
||||
def popleft(self) -> _T: ...
|
||||
def remove(self, __value: _T) -> None: ...
|
||||
def rotate(self, __n: int = ...) -> None: ...
|
||||
def __copy__(self: _S) -> _S: ...
|
||||
def __copy__(self: 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]
|
||||
@@ -206,10 +206,10 @@ class deque(MutableSequence[_T], Generic[_T]):
|
||||
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: _S, __iterable: Iterable[_T]) -> _S: ...
|
||||
def __add__(self: _S, __other: _S) -> _S: ...
|
||||
def __mul__(self: _S, __other: int) -> _S: ...
|
||||
def __imul__(self: _S, __other: int) -> _S: ...
|
||||
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: ...
|
||||
if sys.version_info >= (3, 9):
|
||||
def __class_getitem__(cls, __item: Any) -> GenericAlias: ...
|
||||
|
||||
@@ -306,8 +306,8 @@ class defaultdict(dict[_KT, _VT], Generic[_KT, _VT]):
|
||||
self, __default_factory: Callable[[], _VT] | None, __iterable: Iterable[tuple[_KT, _VT]], **kwargs: _VT
|
||||
) -> None: ...
|
||||
def __missing__(self, __key: _KT) -> _VT: ...
|
||||
def __copy__(self: _S) -> _S: ...
|
||||
def copy(self: _S) -> _S: ...
|
||||
def __copy__(self: Self) -> Self: ...
|
||||
def copy(self: Self) -> Self: ...
|
||||
|
||||
class ChainMap(MutableMapping[_KT, _VT], Generic[_KT, _VT]):
|
||||
maps: list[MutableMapping[_KT, _VT]]
|
||||
|
||||
Reference in New Issue
Block a user