diff --git a/stdlib/asyncio/streams.pyi b/stdlib/asyncio/streams.pyi index 6dae893e3b97..928631ec9a24 100644 --- a/stdlib/asyncio/streams.pyi +++ b/stdlib/asyncio/streams.pyi @@ -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: ... diff --git a/stdlib/codecs.pyi b/stdlib/codecs.pyi index 41f6eae50ebc..2a3e5d72de13 100644 --- a/stdlib/codecs.pyi +++ b/stdlib/codecs.pyi @@ -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 diff --git a/stdlib/csv.pyi b/stdlib/csv.pyi index 13dd603d04a2..4bc21d470747 100644 --- a/stdlib/csv.pyi +++ b/stdlib/csv.pyi @@ -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]): diff --git a/stdlib/fileinput.pyi b/stdlib/fileinput.pyi index 576822059560..04d8ff47d761 100644 --- a/stdlib/fileinput.pyi +++ b/stdlib/fileinput.pyi @@ -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: ... diff --git a/stdlib/pdb.pyi b/stdlib/pdb.pyi index 79dba74edb0d..7764b04bacf6 100644 --- a/stdlib/pdb.pyi +++ b/stdlib/pdb.pyi @@ -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: ... diff --git a/stdlib/sre_constants.pyi b/stdlib/sre_constants.pyi index df7e1a28007b..00644994fe3e 100644 --- a/stdlib/sre_constants.pyi +++ b/stdlib/sre_constants.pyi @@ -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] diff --git a/stdlib/ssl.pyi b/stdlib/ssl.pyi index 8851c94efc16..cd5182de7bd6 100644 --- a/stdlib/ssl.pyi +++ b/stdlib/ssl.pyi @@ -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( diff --git a/stdlib/weakref.pyi b/stdlib/weakref.pyi index e8ee1f482dcb..ee22cddd9aa0 100644 --- a/stdlib/weakref.pyi +++ b/stdlib/weakref.pyi @@ -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]):