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:
Alex Waygood
2022-01-10 03:16:19 +00:00
committed by GitHub
parent 3351f0c0b9
commit 96c9abb058
48 changed files with 295 additions and 321 deletions

View File

@@ -1,5 +1,6 @@
import sys
import types
from _typeshed import Self
from abc import ABCMeta
from builtins import property as _builtins_property
from collections.abc import Iterable, Iterator, Mapping
@@ -32,7 +33,7 @@ class _EnumDict(dict[str, Any]):
class EnumMeta(ABCMeta):
if sys.version_info >= (3, 11):
def __new__(
metacls: type[_T],
metacls: type[Self],
cls: str,
bases: tuple[type, ...],
classdict: _EnumDict,
@@ -40,11 +41,11 @@ class EnumMeta(ABCMeta):
boundary: FlagBoundary | None = ...,
_simple: bool = ...,
**kwds: Any,
) -> _T: ...
) -> Self: ...
elif sys.version_info >= (3, 9):
def __new__(metacls: type[_T], cls: str, bases: tuple[type, ...], classdict: _EnumDict, **kwds: Any) -> _T: ... # type: ignore
def __new__(metacls: type[Self], cls: str, bases: tuple[type, ...], classdict: _EnumDict, **kwds: Any) -> Self: ... # type: ignore
else:
def __new__(metacls: type[_T], cls: str, bases: tuple[type, ...], classdict: _EnumDict) -> _T: ... # type: ignore
def __new__(metacls: type[Self], cls: str, bases: tuple[type, ...], classdict: _EnumDict) -> Self: ... # type: ignore
def __iter__(self: type[_T]) -> Iterator[_T]: ...
def __reversed__(self: type[_T]) -> Iterator[_T]: ...
def __contains__(self: type[Any], member: object) -> bool: ...
@@ -112,7 +113,7 @@ class Enum(metaclass=EnumMeta):
def _missing_(cls, value: object) -> Any: ...
@staticmethod
def _generate_next_value_(name: str, start: int, count: int, last_values: list[Any]) -> Any: ...
def __new__(cls: type[_T], value: object) -> _T: ...
def __new__(cls: type[Self], value: object) -> Self: ...
def __dir__(self) -> list[str]: ...
def __format__(self, format_spec: str) -> str: ...
def __hash__(self) -> Any: ...
@@ -126,7 +127,7 @@ class IntEnum(int, Enum):
else:
@types.DynamicClassAttribute
def value(self) -> int: ...
def __new__(cls: type[_T], value: int | _T) -> _T: ...
def __new__(cls: type[Self], value: int | Self) -> Self: ...
def unique(enumeration: _S) -> _S: ...
@@ -141,7 +142,7 @@ class auto(IntFlag):
else:
@types.DynamicClassAttribute
def value(self) -> Any: ...
def __new__(cls: type[_T]) -> _T: ...
def __new__(cls: type[Self]) -> Self: ...
class Flag(Enum):
_name_: str | None # type: ignore[assignment]
@@ -158,23 +159,23 @@ class Flag(Enum):
def value(self) -> int: ...
def __contains__(self: _T, other: _T) -> bool: ...
def __bool__(self) -> bool: ...
def __or__(self: _T, other: _T) -> _T: ...
def __and__(self: _T, other: _T) -> _T: ...
def __xor__(self: _T, other: _T) -> _T: ...
def __invert__(self: _T) -> _T: ...
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: ...
class IntFlag(int, Flag):
def __new__(cls: type[_T], value: int | _T) -> _T: ...
def __or__(self: _T, other: int | _T) -> _T: ...
def __and__(self: _T, other: int | _T) -> _T: ...
def __xor__(self: _T, other: int | _T) -> _T: ...
def __ror__(self: _T, n: int | _T) -> _T: ...
def __rand__(self: _T, n: int | _T) -> _T: ...
def __rxor__(self: _T, n: int | _T) -> _T: ...
def __new__(cls: type[Self], value: int | Self) -> Self: ...
def __or__(self: Self, other: int | Self) -> Self: ...
def __and__(self: Self, other: int | Self) -> Self: ...
def __xor__(self: Self, other: int | Self) -> Self: ...
def __ror__(self: Self, n: int | Self) -> Self: ...
def __rand__(self: Self, n: int | Self) -> Self: ...
def __rxor__(self: Self, n: int | Self) -> Self: ...
if sys.version_info >= (3, 11):
class StrEnum(str, Enum):
def __new__(cls: type[_T], value: str | _T) -> _T: ...
def __new__(cls: type[Self], value: str | Self) -> Self: ...
_value_: str
@property
def value(self) -> str: ...