mirror of
https://github.com/davidhalter/typeshed.git
synced 2026-02-22 17:48:30 +08:00
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:
@@ -1,3 +1,4 @@
|
||||
from _typeshed import Self
|
||||
from typing import Any, BinaryIO, Callable, ClassVar, Mapping, Sequence, Text, TextIO
|
||||
from typing_extensions import Literal
|
||||
from xml.etree.ElementTree import Element
|
||||
@@ -30,7 +31,7 @@ class Markdown:
|
||||
def registerExtensions(self, extensions: Sequence[Extension | str], configs: Mapping[str, Mapping[str, Any]]) -> Markdown: ...
|
||||
def build_extension(self, ext_name: Text, configs: Mapping[str, str]) -> Extension: ...
|
||||
def registerExtension(self, extension: Extension) -> Markdown: ...
|
||||
def reset(self: Markdown) -> Markdown: ...
|
||||
def reset(self: Self) -> Self: ...
|
||||
def set_output_format(self, format: Literal["xhtml", "html"]) -> Markdown: ...
|
||||
def is_block_level(self, tag: str) -> bool: ...
|
||||
def convert(self, source: Text) -> Text: ...
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
from typing import Any, NoReturn, TypeVar
|
||||
from _typeshed import Self
|
||||
from typing import Any, NoReturn
|
||||
|
||||
from .Image import Image
|
||||
|
||||
_T = TypeVar("_T")
|
||||
|
||||
MAXBLOCK: int
|
||||
SAFEBLOCK: Any
|
||||
LOAD_TRUNCATED_IMAGES: bool
|
||||
@@ -41,7 +40,7 @@ class Parser:
|
||||
def reset(self) -> None: ...
|
||||
decode: Any
|
||||
def feed(self, data) -> None: ...
|
||||
def __enter__(self: _T) -> _T: ...
|
||||
def __enter__(self: Self) -> Self: ...
|
||||
def __exit__(self, *args: Any) -> None: ...
|
||||
def close(self) -> Image: ...
|
||||
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
from typing import Any, Iterable, Iterator, Text, TypeVar
|
||||
from _typeshed import Self
|
||||
from typing import Any, Iterable, Iterator, Text
|
||||
|
||||
from .connections import Connection
|
||||
|
||||
_SelfT = TypeVar("_SelfT")
|
||||
|
||||
class Cursor:
|
||||
connection: Connection[Any]
|
||||
description: tuple[Text, ...]
|
||||
@@ -24,7 +23,7 @@ class Cursor:
|
||||
def executemany(self, query: Text, args: Iterable[object]) -> int | None: ...
|
||||
def callproc(self, procname: Text, args: Iterable[Any] = ...) -> Any: ...
|
||||
def scroll(self, value: int, mode: Text = ...) -> None: ...
|
||||
def __enter__(self: _SelfT) -> _SelfT: ...
|
||||
def __enter__(self: Self) -> Self: ...
|
||||
def __exit__(self, *exc_info: Any) -> None: ...
|
||||
# Methods returning result tuples are below.
|
||||
def fetchone(self) -> tuple[Any, ...] | None: ...
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
from _typeshed import Self
|
||||
from collections.abc import Callable
|
||||
from typing import Any, Generic, TypeVar, overload
|
||||
|
||||
from . import compat
|
||||
|
||||
_R = TypeVar("_R")
|
||||
_T = TypeVar("_T")
|
||||
|
||||
def md5_hex(x): ...
|
||||
|
||||
@@ -65,7 +65,7 @@ class memoized_property(Generic[_R]):
|
||||
__name__: str
|
||||
def __init__(self, fget: Callable[..., _R], doc: str | None = ...) -> None: ...
|
||||
@overload
|
||||
def __get__(self: _T, obj: None, cls: object) -> _T: ...
|
||||
def __get__(self: Self, obj: None, cls: object) -> Self: ...
|
||||
@overload
|
||||
def __get__(self, obj: object, cls: object) -> _R: ...
|
||||
@classmethod
|
||||
@@ -80,7 +80,7 @@ class HasMemoized:
|
||||
__name__: str
|
||||
def __init__(self, fget: Callable[..., _R], doc: str | None = ...) -> None: ...
|
||||
@overload
|
||||
def __get__(self: _T, obj: None, cls: object) -> _T: ...
|
||||
def __get__(self: Self, obj: None, cls: object) -> Self: ...
|
||||
@overload
|
||||
def __get__(self, obj: object, cls: object) -> _R: ...
|
||||
@classmethod
|
||||
@@ -113,7 +113,7 @@ class hybridproperty(Generic[_R]):
|
||||
def __get__(self, instance: None, owner: Any) -> _R: ...
|
||||
@overload
|
||||
def __get__(self, instance: object, owner: object) -> _R: ...
|
||||
def classlevel(self: _T, func: Callable[..., _R]) -> _T: ...
|
||||
def classlevel(self: Self, func: Callable[..., _R]) -> Self: ...
|
||||
|
||||
class hybridmethod:
|
||||
func: Any
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import datetime
|
||||
from typing import Any, Iterator, Text, TypeVar, Union
|
||||
from _typeshed import Self
|
||||
from typing import Any, Iterator, Text, Union
|
||||
from typing_extensions import Literal
|
||||
|
||||
_RetType = Union[type[float], type[datetime.datetime]]
|
||||
_SelfT = TypeVar("_SelfT", bound=croniter)
|
||||
|
||||
class CroniterError(ValueError): ...
|
||||
class CroniterBadCronError(CroniterError): ...
|
||||
@@ -53,7 +53,7 @@ class croniter(Iterator[Any]):
|
||||
def get_prev(self, ret_type: _RetType | None = ...) -> Any: ...
|
||||
def get_current(self, ret_type: _RetType | None = ...) -> Any: ...
|
||||
def set_current(self, start_time: float | datetime.datetime) -> float: ...
|
||||
def __iter__(self: _SelfT) -> _SelfT: ...
|
||||
def __iter__(self: Self) -> Self: ...
|
||||
def __next__(self, ret_type: _RetType | None = ...) -> Any: ...
|
||||
def next(self, ret_type: _RetType | None = ...) -> Any: ...
|
||||
def all_next(self, ret_type: _RetType | None = ...) -> Iterator[Any]: ...
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import sys
|
||||
from _typeshed import Self
|
||||
from types import TracebackType
|
||||
|
||||
class Timeout(TimeoutError):
|
||||
@@ -24,7 +25,7 @@ class BaseFileLock:
|
||||
def is_locked(self) -> bool: ...
|
||||
def acquire(self, timeout: float | None = ..., poll_intervall: float = ...) -> _Acquire_ReturnProxy: ...
|
||||
def release(self, force: bool = ...) -> None: ...
|
||||
def __enter__(self) -> BaseFileLock: ...
|
||||
def __enter__(self: Self) -> Self: ...
|
||||
def __exit__(
|
||||
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, traceback: TracebackType | None
|
||||
) -> None: ...
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import collections
|
||||
from _typeshed import Self
|
||||
from typing import Any, Generic, Iterable, Iterator, Mapping, TypeVar, overload
|
||||
|
||||
_S = TypeVar("_S")
|
||||
_KT = TypeVar("_KT")
|
||||
_VT = TypeVar("_VT")
|
||||
|
||||
@@ -16,7 +16,7 @@ class frozendict(Mapping[_KT, _VT], Generic[_KT, _VT]):
|
||||
def __init__(self, iterable: Iterable[tuple[_KT, _VT]]) -> None: ...
|
||||
def __getitem__(self, key: _KT) -> _VT: ...
|
||||
def __contains__(self, key: object) -> bool: ...
|
||||
def copy(self: _S, **add_or_replace: _VT) -> _S: ...
|
||||
def copy(self: Self, **add_or_replace: _VT) -> Self: ...
|
||||
def __iter__(self) -> Iterator[_KT]: ...
|
||||
def __len__(self) -> int: ...
|
||||
def __repr__(self) -> str: ...
|
||||
|
||||
@@ -1,20 +1,19 @@
|
||||
import socket
|
||||
from typing import Any, TypeVar
|
||||
|
||||
_T = TypeVar("_T")
|
||||
from _typeshed import Self
|
||||
from typing import Any
|
||||
|
||||
class LDAPException(Exception): ...
|
||||
|
||||
class LDAPOperationResult(LDAPException):
|
||||
def __new__(
|
||||
cls: type[_T],
|
||||
cls: type[Self],
|
||||
result: Any | None = ...,
|
||||
description: Any | None = ...,
|
||||
dn: Any | None = ...,
|
||||
message: Any | None = ...,
|
||||
response_type: Any | None = ...,
|
||||
response: Any | None = ...,
|
||||
) -> _T: ...
|
||||
) -> Self: ...
|
||||
result: Any
|
||||
description: Any
|
||||
dn: Any
|
||||
|
||||
@@ -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]: ...
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
from _typeshed import Self
|
||||
from types import TracebackType
|
||||
|
||||
from .scope_manager import ScopeManager
|
||||
@@ -10,7 +11,7 @@ class Scope:
|
||||
@property
|
||||
def manager(self) -> ScopeManager: ...
|
||||
def close(self) -> None: ...
|
||||
def __enter__(self) -> Scope: ...
|
||||
def __enter__(self: Self) -> Self: ...
|
||||
def __exit__(
|
||||
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
|
||||
) -> None: ...
|
||||
|
||||
@@ -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: ...
|
||||
|
||||
@@ -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: ...
|
||||
|
||||
@@ -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: ...
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import sys
|
||||
from _typeshed import Self
|
||||
from contextlib import AbstractContextManager
|
||||
from typing import Any, Callable, Iterable, Iterator, TypeVar
|
||||
from typing import Any, Callable, Iterable, Iterator
|
||||
|
||||
from ._common import (
|
||||
AIX as AIX,
|
||||
@@ -177,11 +178,9 @@ class Process:
|
||||
def kill(self) -> None: ...
|
||||
def wait(self, timeout: int | None = ...) -> int: ...
|
||||
|
||||
_Popen = TypeVar("_Popen", bound="Popen")
|
||||
|
||||
class Popen(Process):
|
||||
def __init__(self, *args, **kwargs) -> None: ...
|
||||
def __enter__(self: _Popen) -> _Popen: ...
|
||||
def __enter__(self: Self) -> Self: ...
|
||||
def __exit__(self, *args, **kwargs) -> None: ...
|
||||
def __getattribute__(self, name: str) -> Any: ...
|
||||
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
from typing import TypeVar
|
||||
|
||||
_T = TypeVar("_T")
|
||||
from _typeshed import Self
|
||||
|
||||
class weekday(object):
|
||||
def __init__(self, weekday: int, n: int | None = ...) -> None: ...
|
||||
def __call__(self: _T, n: int) -> _T: ...
|
||||
def __call__(self: Self, n: int) -> Self: ...
|
||||
def __eq__(self, other: object) -> bool: ...
|
||||
def __repr__(self) -> str: ...
|
||||
def __hash__(self) -> int: ...
|
||||
|
||||
@@ -680,7 +680,7 @@ class Monitor:
|
||||
command_re: Pattern[str]
|
||||
monitor_re: Pattern[str]
|
||||
def __init__(self, connection_pool) -> None: ...
|
||||
def __enter__(self) -> Monitor: ...
|
||||
def __enter__(self: Self) -> Self: ...
|
||||
def __exit__(self, *args: Any) -> None: ...
|
||||
def next_command(self) -> dict[str, Any]: ...
|
||||
def listen(self) -> Iterable[dict[str, Any]]: ...
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
from _typeshed import Self
|
||||
from types import TracebackType
|
||||
from typing import Any, ClassVar, Protocol
|
||||
|
||||
@@ -25,7 +26,7 @@ class Lock:
|
||||
thread_local: bool = ...,
|
||||
) -> None: ...
|
||||
def register_scripts(self) -> None: ...
|
||||
def __enter__(self) -> Lock: ...
|
||||
def __enter__(self: Self) -> Self: ...
|
||||
def __exit__(
|
||||
self, exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: TracebackType | None
|
||||
) -> bool | None: ...
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import datetime
|
||||
from _typeshed import Self
|
||||
from json import JSONDecoder
|
||||
from typing import Any, Callable, Iterator, Text, TypeVar
|
||||
|
||||
@@ -106,7 +107,7 @@ class Response:
|
||||
def __bool__(self) -> bool: ...
|
||||
def __nonzero__(self) -> bool: ...
|
||||
def __iter__(self) -> Iterator[bytes]: ...
|
||||
def __enter__(self) -> Response: ...
|
||||
def __enter__(self: Self) -> Self: ...
|
||||
def __exit__(self, *args: Any) -> None: ...
|
||||
@property
|
||||
def next(self) -> PreparedRequest | None: ...
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from _typeshed import SupportsItems
|
||||
from _typeshed import Self, SupportsItems
|
||||
from typing import IO, Any, Callable, Iterable, Mapping, MutableMapping, Optional, Text, TypeVar, Union
|
||||
|
||||
from urllib3 import _collections
|
||||
@@ -62,7 +62,6 @@ _Params = Union[
|
||||
Union[Text, bytes],
|
||||
]
|
||||
_TextMapping = MutableMapping[Text, Text]
|
||||
_SessionT = TypeVar("_SessionT", bound=Session)
|
||||
|
||||
class Session(SessionRedirectMixin):
|
||||
__attrs__: Any
|
||||
@@ -80,7 +79,7 @@ class Session(SessionRedirectMixin):
|
||||
adapters: MutableMapping[Any, Any]
|
||||
redirect_cache: RecentlyUsedContainer[Any, Any]
|
||||
def __init__(self) -> None: ...
|
||||
def __enter__(self: _SessionT) -> _SessionT: ...
|
||||
def __enter__(self: Self) -> Self: ...
|
||||
def __exit__(self, *args) -> None: ...
|
||||
def prepare_request(self, request: Request) -> PreparedRequest: ...
|
||||
def request(
|
||||
|
||||
Reference in New Issue
Block a user