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,12 +1,11 @@
import builtins
import ctypes
import sys
from _typeshed import Self
from types import TracebackType
from typing import Any, TypeVar
from typing import Any
if sys.platform == "win32":
_T = TypeVar("_T")
def format_system_message(errno: int) -> str | None: ...
class WindowsError(builtins.WindowsError):
def __init__(self, value: int | None = ...) -> None: ...
@@ -32,7 +31,7 @@ if sys.platform == "win32":
filemap: Any = ...
view: Any = ...
def __init__(self, name: str, length: int, security_attributes: Any | None = ...) -> None: ...
def __enter__(self: _T) -> _T: ...
def __enter__(self: Self) -> Self: ...
def seek(self, pos: int) -> None: ...
def write(self, msg: bytes) -> None: ...
def read(self, n: int) -> bytes: ...

View File

@@ -1,4 +1,5 @@
from typing import IO, Pattern, TypeVar
from _typeshed import Self
from typing import IO, Pattern
from paramiko.message import Message
@@ -6,8 +7,6 @@ OPENSSH_AUTH_MAGIC: bytes = ...
def _unpad_openssh(data: bytes) -> bytes: ...
_PK = TypeVar("_PK", bound=PKey)
class PKey:
public_blob: PublicBlob | None
BEGIN_TAG: Pattern[str]
@@ -24,9 +23,9 @@ class PKey:
def sign_ssh_data(self, data: bytes) -> Message: ...
def verify_ssh_sig(self, data: bytes, msg: Message) -> bool: ...
@classmethod
def from_private_key_file(cls: type[_PK], filename: str, password: str | None = ...) -> _PK: ...
def from_private_key_file(cls: type[Self], filename: str, password: str | None = ...) -> Self: ...
@classmethod
def from_private_key(cls: type[_PK], file_obj: IO[str], password: str | None = ...) -> _PK: ...
def from_private_key(cls: type[Self], file_obj: IO[str], password: str | None = ...) -> Self: ...
def write_private_key_file(self, filename: str, password: str | None = ...) -> None: ...
def write_private_key(self, file_obj: IO[str], password: str | None = ...) -> None: ...
def load_certificate(self, value: Message | str) -> None: ...

View File

@@ -1,4 +1,5 @@
import sys
from _typeshed import Self
from logging import Logger, LogRecord
from types import TracebackType
from typing import IO, AnyStr, Callable, Protocol, TypeVar
@@ -15,7 +16,6 @@ class SupportsClose(Protocol):
def close(self) -> None: ...
_T = TypeVar("_T")
_TC = TypeVar("_TC", bound=SupportsClose)
def inflate_long(s: bytes, always_positive: bool = ...) -> int: ...
@@ -44,7 +44,7 @@ def retry_on_signal(function: Callable[[], _T]) -> _T: ...
def constant_time_bytes_eq(a: AnyStr, b: AnyStr) -> bool: ...
class ClosingContextManager:
def __enter__(self: _TC) -> _TC: ...
def __enter__(self: Self) -> Self: ...
def __exit__(
self, type: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None
) -> None: ...