mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-07 12:44:28 +08:00
Fix return annotations of several methods that return self at runtime (#7070)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import sys
|
||||
from _typeshed import StrPath
|
||||
from _typeshed import Self, StrPath
|
||||
from typing import Any, AsyncIterator, Awaitable, Callable, Iterable, Optional
|
||||
|
||||
from . import events, protocols, transports
|
||||
@@ -117,7 +117,7 @@ class StreamWriter:
|
||||
def get_extra_info(self, name: str, default: Any = ...) -> Any: ...
|
||||
async def drain(self) -> None: ...
|
||||
|
||||
class StreamReader:
|
||||
class StreamReader(AsyncIterator[bytes]):
|
||||
def __init__(self, limit: int = ..., loop: events.AbstractEventLoop | None = ...) -> None: ...
|
||||
def exception(self) -> Exception: ...
|
||||
def set_exception(self, exc: Exception) -> None: ...
|
||||
@@ -129,5 +129,5 @@ class StreamReader:
|
||||
async def readuntil(self, separator: bytes = ...) -> bytes: ...
|
||||
async def read(self, n: int = ...) -> bytes: ...
|
||||
async def readexactly(self, n: int) -> bytes: ...
|
||||
def __aiter__(self) -> AsyncIterator[bytes]: ...
|
||||
def __aiter__(self: Self) -> Self: ...
|
||||
async def __anext__(self) -> bytes: ...
|
||||
|
||||
@@ -86,7 +86,7 @@ class CodecInfo(tuple[_Encoder, _Decoder, _StreamReader, _StreamWriter]):
|
||||
def incrementaldecoder(self) -> _IncrementalDecoder: ...
|
||||
name: str
|
||||
def __new__(
|
||||
cls,
|
||||
cls: type[Self],
|
||||
encode: _Encoder,
|
||||
decode: _Decoder,
|
||||
streamreader: _StreamReader | None = ...,
|
||||
@@ -96,7 +96,7 @@ class CodecInfo(tuple[_Encoder, _Decoder, _StreamReader, _StreamWriter]):
|
||||
name: str | None = ...,
|
||||
*,
|
||||
_is_text_encoding: bool | None = ...,
|
||||
) -> CodecInfo: ...
|
||||
) -> Self: ...
|
||||
|
||||
def getencoder(encoding: str) -> _Encoder: ...
|
||||
def getdecoder(encoding: str) -> _Decoder: ...
|
||||
@@ -189,7 +189,7 @@ class StreamWriter(Codec):
|
||||
def __exit__(self, typ: type[BaseException] | None, exc: BaseException | None, tb: types.TracebackType | None) -> None: ...
|
||||
def __getattr__(self, name: str, getattr: Callable[[str], Any] = ...) -> Any: ...
|
||||
|
||||
class StreamReader(Codec):
|
||||
class StreamReader(Codec, Iterator[str]):
|
||||
errors: str
|
||||
def __init__(self, stream: IO[bytes], errors: str = ...) -> None: ...
|
||||
def read(self, size: int = ..., chars: int = ..., firstline: bool = ...) -> str: ...
|
||||
@@ -198,7 +198,8 @@ class StreamReader(Codec):
|
||||
def reset(self) -> None: ...
|
||||
def __enter__(self: Self) -> Self: ...
|
||||
def __exit__(self, typ: type[BaseException] | None, exc: BaseException | None, tb: types.TracebackType | None) -> None: ...
|
||||
def __iter__(self) -> Iterator[str]: ...
|
||||
def __iter__(self: Self) -> Self: ...
|
||||
def __next__(self) -> str: ...
|
||||
def __getattr__(self, name: str, getattr: Callable[[str], Any] = ...) -> Any: ...
|
||||
|
||||
# Doesn't actually inherit from TextIO, but wraps a BinaryIO to provide text reading and writing
|
||||
|
||||
@@ -17,6 +17,7 @@ from _csv import (
|
||||
unregister_dialect as unregister_dialect,
|
||||
writer as writer,
|
||||
)
|
||||
from _typeshed import Self
|
||||
from collections.abc import Collection, Iterable, Iterator, Mapping, Sequence
|
||||
from typing import Any, Generic, TypeVar, overload
|
||||
|
||||
@@ -75,7 +76,7 @@ class DictReader(Generic[_T], Iterator[_DictReadMapping[_T, str]]):
|
||||
*args: Any,
|
||||
**kwds: Any,
|
||||
) -> None: ...
|
||||
def __iter__(self) -> DictReader[_T]: ...
|
||||
def __iter__(self: Self) -> Self: ...
|
||||
def __next__(self) -> _DictReadMapping[_T, str]: ...
|
||||
|
||||
class DictWriter(Generic[_T]):
|
||||
|
||||
@@ -46,7 +46,7 @@ def fileno() -> int: ...
|
||||
def isfirstline() -> bool: ...
|
||||
def isstdin() -> bool: ...
|
||||
|
||||
class FileInput(Iterable[AnyStr], Generic[AnyStr]):
|
||||
class FileInput(Iterator[AnyStr], Generic[AnyStr]):
|
||||
if sys.version_info >= (3, 10):
|
||||
def __init__(
|
||||
self,
|
||||
@@ -83,7 +83,7 @@ class FileInput(Iterable[AnyStr], Generic[AnyStr]):
|
||||
def close(self) -> None: ...
|
||||
def __enter__(self: Self) -> Self: ...
|
||||
def __exit__(self, type: Any, value: Any, traceback: Any) -> None: ...
|
||||
def __iter__(self) -> Iterator[AnyStr]: ...
|
||||
def __iter__(self: Self) -> Self: ...
|
||||
def __next__(self) -> AnyStr: ...
|
||||
if sys.version_info < (3, 11):
|
||||
def __getitem__(self, i: int) -> AnyStr: ...
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import signal
|
||||
import sys
|
||||
from _typeshed import Self
|
||||
from bdb import Bdb
|
||||
from cmd import Cmd
|
||||
from inspect import _SourceObjectType
|
||||
@@ -173,4 +174,4 @@ def getsourcelines(obj: _SourceObjectType) -> tuple[list[str], int]: ...
|
||||
def lasti2lineno(code: CodeType, lasti: int) -> int: ...
|
||||
|
||||
class _rstr(str):
|
||||
def __repr__(self) -> _rstr: ...
|
||||
def __repr__(self: Self) -> Self: ...
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import sys
|
||||
from _typeshed import Self
|
||||
from typing import Any
|
||||
|
||||
MAXGROUPS: int
|
||||
@@ -15,7 +16,7 @@ class error(Exception):
|
||||
|
||||
class _NamedIntConstant(int):
|
||||
name: Any
|
||||
def __new__(cls, value: int, name: str) -> _NamedIntConstant: ...
|
||||
def __new__(cls: type[Self], value: int, name: str) -> Self: ...
|
||||
|
||||
MAXREPEAT: _NamedIntConstant
|
||||
OPCODES: list[_NamedIntConstant]
|
||||
|
||||
@@ -396,7 +396,7 @@ class SSLContext:
|
||||
if sys.version_info >= (3, 8):
|
||||
keylog_filename: str
|
||||
post_handshake_auth: bool
|
||||
def __new__(cls, protocol: int = ..., *args: Any, **kwargs: Any) -> SSLContext: ...
|
||||
def __new__(cls: type[Self], protocol: int = ..., *args: Any, **kwargs: Any) -> Self: ...
|
||||
def __init__(self, protocol: int = ...) -> None: ...
|
||||
def cert_store_stats(self) -> dict[str, int]: ...
|
||||
def load_cert_chain(
|
||||
|
||||
@@ -25,7 +25,7 @@ _P = ParamSpec("_P")
|
||||
ProxyTypes: tuple[type[Any], ...]
|
||||
|
||||
class WeakMethod(ref[_CallableT], Generic[_CallableT]):
|
||||
def __new__(cls, meth: _CallableT, callback: Callable[[_CallableT], object] | None = ...) -> WeakMethod[_CallableT]: ...
|
||||
def __new__(cls: type[Self], meth: _CallableT, callback: Callable[[_CallableT], object] | None = ...) -> Self: ...
|
||||
def __call__(self) -> _CallableT | None: ...
|
||||
|
||||
class WeakValueDictionary(MutableMapping[_KT, _VT]):
|
||||
@@ -67,7 +67,7 @@ class WeakValueDictionary(MutableMapping[_KT, _VT]):
|
||||
class KeyedRef(ref[_T], Generic[_KT, _T]):
|
||||
key: _KT
|
||||
# This __new__ method uses a non-standard name for the "cls" parameter
|
||||
def __new__(type, ob: _T, callback: Callable[[_T], Any], key: _KT) -> KeyedRef[_KT, _T]: ... # type: ignore
|
||||
def __new__(type: type[Self], ob: _T, callback: Callable[[_T], Any], key: _KT) -> Self: ... # type: ignore
|
||||
def __init__(self, ob: _T, callback: Callable[[_T], Any], key: _KT) -> None: ...
|
||||
|
||||
class WeakKeyDictionary(MutableMapping[_KT, _VT]):
|
||||
|
||||
Reference in New Issue
Block a user