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

@@ -5,11 +5,9 @@ from _typeshed import Self, StrOrBytesPath, StrPath
from collections.abc import Callable, Iterable, Iterator, Mapping
from gzip import _ReadableFileobj as _GzipReadableFileobj, _WritableFileobj as _GzipWritableFileobj
from types import TracebackType
from typing import IO, Protocol, TypeVar, overload
from typing import IO, Protocol, overload
from typing_extensions import Literal
_TF = TypeVar("_TF", bound=TarFile)
class _Fileobj(Protocol):
def read(self, __size: int) -> bytes: ...
def write(self, __b: bytes) -> object: ...
@@ -133,7 +131,7 @@ class TarFile:
def __iter__(self) -> Iterator[TarInfo]: ...
@classmethod
def open(
cls: type[_TF],
cls: type[Self],
name: StrOrBytesPath | None = ...,
mode: str = ...,
fileobj: IO[bytes] | None = ..., # depends on mode
@@ -148,10 +146,10 @@ class TarFile:
pax_headers: Mapping[str, str] | None = ...,
debug: int | None = ...,
errorlevel: int | None = ...,
) -> _TF: ...
) -> Self: ...
@classmethod
def taropen(
cls: type[_TF],
cls: type[Self],
name: StrOrBytesPath | None,
mode: Literal["r", "a", "w", "x"] = ...,
fileobj: _Fileobj | None = ...,
@@ -165,11 +163,11 @@ class TarFile:
pax_headers: Mapping[str, str] | None = ...,
debug: int | None = ...,
errorlevel: int | None = ...,
) -> _TF: ...
) -> Self: ...
@overload
@classmethod
def gzopen(
cls: type[_TF],
cls: type[Self],
name: StrOrBytesPath | None,
mode: Literal["r"] = ...,
fileobj: _GzipReadableFileobj | None = ...,
@@ -183,11 +181,11 @@ class TarFile:
pax_headers: Mapping[str, str] | None = ...,
debug: int | None = ...,
errorlevel: int | None = ...,
) -> _TF: ...
) -> Self: ...
@overload
@classmethod
def gzopen(
cls: type[_TF],
cls: type[Self],
name: StrOrBytesPath | None,
mode: Literal["w", "x"],
fileobj: _GzipWritableFileobj | None = ...,
@@ -201,11 +199,11 @@ class TarFile:
pax_headers: Mapping[str, str] | None = ...,
debug: int | None = ...,
errorlevel: int | None = ...,
) -> _TF: ...
) -> Self: ...
@overload
@classmethod
def bz2open(
cls: type[_TF],
cls: type[Self],
name: StrOrBytesPath | None,
mode: Literal["w", "x"],
fileobj: _Bz2WritableFileobj | None = ...,
@@ -219,11 +217,11 @@ class TarFile:
pax_headers: Mapping[str, str] | None = ...,
debug: int | None = ...,
errorlevel: int | None = ...,
) -> _TF: ...
) -> Self: ...
@overload
@classmethod
def bz2open(
cls: type[_TF],
cls: type[Self],
name: StrOrBytesPath | None,
mode: Literal["r"] = ...,
fileobj: _Bz2ReadableFileobj | None = ...,
@@ -237,10 +235,10 @@ class TarFile:
pax_headers: Mapping[str, str] | None = ...,
debug: int | None = ...,
errorlevel: int | None = ...,
) -> _TF: ...
) -> Self: ...
@classmethod
def xzopen(
cls: type[_TF],
cls: type[Self],
name: StrOrBytesPath | None,
mode: Literal["r", "w", "x"] = ...,
fileobj: IO[bytes] | None = ...,
@@ -254,7 +252,7 @@ class TarFile:
pax_headers: Mapping[str, str] | None = ...,
debug: int | None = ...,
errorlevel: int | None = ...,
) -> _TF: ...
) -> Self: ...
def getmember(self, name: str) -> TarInfo: ...
def getmembers(self) -> _list[TarInfo]: ...
def getnames(self) -> _list[str]: ...