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

@@ -2,7 +2,7 @@ import sys
import types
from _typeshed import Self
from abc import abstractmethod
from typing import IO, Any, BinaryIO, Callable, Generator, Iterable, Iterator, Protocol, TextIO, TypeVar, overload
from typing import IO, Any, BinaryIO, Callable, Generator, Iterable, Iterator, Protocol, TextIO, overload
from typing_extensions import Literal
BOM32_BE: Literal[b"\xfe\xff"]
@@ -201,8 +201,6 @@ class StreamReader(Codec):
def __iter__(self) -> Iterator[str]: ...
def __getattr__(self, name: str, getattr: Callable[[str], Any] = ...) -> Any: ...
_T = TypeVar("_T", bound=StreamReaderWriter)
# Doesn't actually inherit from TextIO, but wraps a BinaryIO to provide text reading and writing
# and delegates attributes to the underlying binary stream with __getattr__.
class StreamReaderWriter(TextIO):
@@ -211,7 +209,7 @@ class StreamReaderWriter(TextIO):
def readline(self, size: int | None = ...) -> str: ...
def readlines(self, sizehint: int | None = ...) -> list[str]: ...
def __next__(self) -> str: ...
def __iter__(self: _T) -> _T: ...
def __iter__(self: Self) -> Self: ...
# This actually returns None, but that's incompatible with the supertype
def write(self, data: str) -> int: ...
def writelines(self, list: Iterable[str]) -> None: ...
@@ -233,8 +231,6 @@ class StreamReaderWriter(TextIO):
def tell(self) -> int: ...
def writable(self) -> bool: ...
_SRT = TypeVar("_SRT", bound=StreamRecoder)
class StreamRecoder(BinaryIO):
def __init__(
self,
@@ -249,7 +245,7 @@ class StreamRecoder(BinaryIO):
def readline(self, size: int | None = ...) -> bytes: ...
def readlines(self, sizehint: int | None = ...) -> list[bytes]: ...
def __next__(self) -> bytes: ...
def __iter__(self: _SRT) -> _SRT: ...
def __iter__(self: Self) -> Self: ...
def write(self, data: bytes) -> int: ...
def writelines(self, list: Iterable[bytes]) -> int: ... # type: ignore # it's supposed to return None
def reset(self) -> None: ...