mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-09 13:34:58 +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:
@@ -69,8 +69,6 @@ _T2 = TypeVar("_T2")
|
||||
_T3 = TypeVar("_T3")
|
||||
_T4 = TypeVar("_T4")
|
||||
_T5 = TypeVar("_T5")
|
||||
_TT = TypeVar("_TT", bound="type")
|
||||
_TBE = TypeVar("_TBE", bound="BaseException")
|
||||
_R = TypeVar("_R") # Return-type TypeVar
|
||||
_SupportsNextT = TypeVar("_SupportsNextT", bound=SupportsNext[Any], covariant=True)
|
||||
_SupportsAnextT = TypeVar("_SupportsAnextT", bound=SupportsAnext[Any], covariant=True)
|
||||
@@ -87,12 +85,12 @@ class object:
|
||||
__module__: str
|
||||
__annotations__: dict[str, Any]
|
||||
@property
|
||||
def __class__(self: _T) -> type[_T]: ...
|
||||
def __class__(self: Self) -> type[Self]: ...
|
||||
# Ignore errors about type mismatch between property getter and setter
|
||||
@__class__.setter
|
||||
def __class__(self, __type: type[object]) -> None: ... # type: ignore # noqa: F811
|
||||
def __init__(self) -> None: ...
|
||||
def __new__(cls: type[_T]) -> _T: ...
|
||||
def __new__(cls: type[Self]) -> Self: ...
|
||||
def __setattr__(self, __name: str, __value: Any) -> None: ...
|
||||
def __eq__(self, __o: object) -> bool: ...
|
||||
def __ne__(self, __o: object) -> bool: ...
|
||||
@@ -117,7 +115,7 @@ class staticmethod(Generic[_R]): # Special, only valid as a decorator.
|
||||
__func__: Callable[..., _R]
|
||||
__isabstractmethod__: bool
|
||||
def __init__(self: staticmethod[_R], __f: Callable[..., _R]) -> None: ...
|
||||
def __new__(cls: type[_T], *args: Any, **kwargs: Any) -> _T: ...
|
||||
def __new__(cls: type[Self], *args: Any, **kwargs: Any) -> Self: ...
|
||||
def __get__(self, __obj: _T, __type: type[_T] | None = ...) -> Callable[..., _R]: ...
|
||||
if sys.version_info >= (3, 10):
|
||||
__name__: str
|
||||
@@ -129,7 +127,7 @@ class classmethod(Generic[_R]): # Special, only valid as a decorator.
|
||||
__func__: Callable[..., _R]
|
||||
__isabstractmethod__: bool
|
||||
def __init__(self: classmethod[_R], __f: Callable[..., _R]) -> None: ...
|
||||
def __new__(cls: type[_T], *args: Any, **kwargs: Any) -> _T: ...
|
||||
def __new__(cls: type[Self], *args: Any, **kwargs: Any) -> Self: ...
|
||||
def __get__(self, __obj: _T, __type: type[_T] | None = ...) -> Callable[..., _R]: ...
|
||||
if sys.version_info >= (3, 10):
|
||||
__name__: str
|
||||
@@ -157,9 +155,9 @@ class type:
|
||||
@overload
|
||||
def __new__(cls, __o: object) -> type: ...
|
||||
@overload
|
||||
def __new__(cls: type[_TT], __name: str, __bases: tuple[type, ...], __namespace: dict[str, Any], **kwds: Any) -> _TT: ...
|
||||
def __new__(cls: type[Self], __name: str, __bases: tuple[type, ...], __namespace: dict[str, Any], **kwds: Any) -> Self: ...
|
||||
def __call__(self, *args: Any, **kwds: Any) -> Any: ...
|
||||
def __subclasses__(self: _TT) -> list[_TT]: ...
|
||||
def __subclasses__(self: Self) -> list[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]: ...
|
||||
@@ -184,9 +182,9 @@ _NegativeInteger = Literal[-1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -1
|
||||
|
||||
class int:
|
||||
@overload
|
||||
def __new__(cls: type[_T], __x: str | bytes | SupportsInt | SupportsIndex | SupportsTrunc = ...) -> _T: ...
|
||||
def __new__(cls: type[Self], __x: str | bytes | SupportsInt | SupportsIndex | SupportsTrunc = ...) -> Self: ...
|
||||
@overload
|
||||
def __new__(cls: type[_T], __x: str | bytes | bytearray, base: SupportsIndex) -> _T: ...
|
||||
def __new__(cls: type[Self], __x: str | bytes | bytearray, base: SupportsIndex) -> Self: ...
|
||||
if sys.version_info >= (3, 8):
|
||||
def as_integer_ratio(self) -> tuple[int, Literal[1]]: ...
|
||||
@property
|
||||
@@ -269,7 +267,7 @@ class int:
|
||||
def __index__(self) -> int: ...
|
||||
|
||||
class float:
|
||||
def __new__(cls: type[_T], x: SupportsFloat | SupportsIndex | str | bytes | bytearray = ...) -> _T: ...
|
||||
def __new__(cls: type[Self], x: SupportsFloat | SupportsIndex | str | bytes | bytearray = ...) -> Self: ...
|
||||
def as_integer_ratio(self) -> tuple[int, int]: ...
|
||||
def hex(self) -> str: ...
|
||||
def is_integer(self) -> bool: ...
|
||||
@@ -326,9 +324,9 @@ class float:
|
||||
|
||||
class complex:
|
||||
@overload
|
||||
def __new__(cls: type[_T], real: float = ..., imag: float = ...) -> _T: ...
|
||||
def __new__(cls: type[Self], real: float = ..., imag: float = ...) -> Self: ...
|
||||
@overload
|
||||
def __new__(cls: type[_T], real: str | SupportsComplex | SupportsIndex | complex) -> _T: ...
|
||||
def __new__(cls: type[Self], real: str | SupportsComplex | SupportsIndex | complex) -> Self: ...
|
||||
@property
|
||||
def real(self) -> float: ...
|
||||
@property
|
||||
@@ -359,9 +357,9 @@ class _FormatMapMapping(Protocol):
|
||||
|
||||
class str(Sequence[str]):
|
||||
@overload
|
||||
def __new__(cls: type[_T], object: object = ...) -> _T: ...
|
||||
def __new__(cls: type[Self], object: object = ...) -> Self: ...
|
||||
@overload
|
||||
def __new__(cls: type[_T], o: bytes, encoding: str = ..., errors: str = ...) -> _T: ...
|
||||
def __new__(cls: type[Self], o: bytes, encoding: str = ..., errors: str = ...) -> Self: ...
|
||||
def capitalize(self) -> str: ...
|
||||
def casefold(self) -> str: ...
|
||||
def center(self, __width: SupportsIndex, __fillchar: str = ...) -> str: ...
|
||||
@@ -443,15 +441,15 @@ class str(Sequence[str]):
|
||||
|
||||
class bytes(ByteString):
|
||||
@overload
|
||||
def __new__(cls: type[_T], __ints: Iterable[SupportsIndex]) -> _T: ...
|
||||
def __new__(cls: type[Self], __ints: Iterable[SupportsIndex]) -> Self: ...
|
||||
@overload
|
||||
def __new__(cls: type[_T], __string: str, encoding: str, errors: str = ...) -> _T: ...
|
||||
def __new__(cls: type[Self], __string: str, encoding: str, errors: str = ...) -> Self: ...
|
||||
@overload
|
||||
def __new__(cls: type[_T], __length: SupportsIndex) -> _T: ...
|
||||
def __new__(cls: type[Self], __length: SupportsIndex) -> Self: ...
|
||||
@overload
|
||||
def __new__(cls: type[_T]) -> _T: ...
|
||||
def __new__(cls: type[Self]) -> Self: ...
|
||||
@overload
|
||||
def __new__(cls: type[_T], __o: SupportsBytes) -> _T: ...
|
||||
def __new__(cls: type[Self], __o: SupportsBytes) -> Self: ...
|
||||
def capitalize(self) -> bytes: ...
|
||||
def center(self, __width: SupportsIndex, __fillchar: bytes = ...) -> bytes: ...
|
||||
def count(
|
||||
@@ -705,7 +703,7 @@ class memoryview(Sized, Sequence[int]):
|
||||
|
||||
@final
|
||||
class bool(int):
|
||||
def __new__(cls: type[_T], __o: object = ...) -> _T: ...
|
||||
def __new__(cls: type[Self], __o: object = ...) -> Self: ...
|
||||
@overload
|
||||
def __and__(self, __x: bool) -> bool: ...
|
||||
@overload
|
||||
@@ -748,7 +746,7 @@ class slice:
|
||||
def indices(self, __len: SupportsIndex) -> tuple[int, int, int]: ...
|
||||
|
||||
class tuple(Sequence[_T_co], Generic[_T_co]):
|
||||
def __new__(cls: type[_T], __iterable: Iterable[_T_co] = ...) -> _T: ...
|
||||
def __new__(cls: type[Self], __iterable: Iterable[_T_co] = ...) -> Self: ...
|
||||
def __len__(self) -> int: ...
|
||||
def __contains__(self, __x: object) -> bool: ...
|
||||
@overload
|
||||
@@ -820,10 +818,10 @@ class list(MutableSequence[_T], Generic[_T]):
|
||||
def __setitem__(self, __s: slice, __o: Iterable[_T]) -> None: ...
|
||||
def __delitem__(self, __i: SupportsIndex | slice) -> None: ...
|
||||
def __add__(self, __x: list[_T]) -> list[_T]: ...
|
||||
def __iadd__(self: _S, __x: Iterable[_T]) -> _S: ...
|
||||
def __iadd__(self: Self, __x: Iterable[_T]) -> Self: ...
|
||||
def __mul__(self, __n: SupportsIndex) -> list[_T]: ...
|
||||
def __rmul__(self, __n: SupportsIndex) -> list[_T]: ...
|
||||
def __imul__(self: _S, __n: SupportsIndex) -> _S: ...
|
||||
def __imul__(self: Self, __n: SupportsIndex) -> Self: ...
|
||||
def __contains__(self, __o: object) -> bool: ...
|
||||
def __reversed__(self) -> Iterator[_T]: ...
|
||||
def __gt__(self, __x: list[_T]) -> bool: ...
|
||||
@@ -847,7 +845,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[_T1], *args: Any, **kwargs: Any) -> _T1: ...
|
||||
def __new__(cls: type[Self], *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]: ...
|
||||
@@ -1523,7 +1521,7 @@ class BaseException:
|
||||
if sys.version_info >= (3, 11):
|
||||
__note__: str | None
|
||||
def __init__(self, *args: object) -> None: ...
|
||||
def with_traceback(self: _TBE, __tb: TracebackType | None) -> _TBE: ...
|
||||
def with_traceback(self: Self, __tb: TracebackType | None) -> Self: ...
|
||||
|
||||
class GeneratorExit(BaseException): ...
|
||||
class KeyboardInterrupt(BaseException): ...
|
||||
|
||||
Reference in New Issue
Block a user