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 abc
import sys
from _typeshed import Self
from typing import Any, Callable, Generic, ItemsView, KeysView, Mapping, TypeVar, ValuesView
_T = TypeVar("_T")
@@ -7,13 +8,13 @@ _U = TypeVar("_U")
# Internal mypy fallback type for all typed dicts (does not exist at runtime)
class _TypedDict(Mapping[str, object], metaclass=abc.ABCMeta):
def copy(self: _T) -> _T: ...
def copy(self: Self) -> Self: ...
# Using NoReturn so that only calls using mypy plugin hook that specialize the signature
# can go through.
def setdefault(self, k: NoReturn, default: object) -> object: ...
# Mypy plugin hook for 'pop' expects that 'default' has a type variable type.
def pop(self, k: NoReturn, default: _T = ...) -> object: ... # type: ignore
def update(self: _T, __m: _T) -> None: ...
def update(self: Self, __m: Self) -> None: ...
if sys.version_info >= (3, 0):
def items(self) -> ItemsView[str, object]: ...
def keys(self) -> KeysView[str]: ...