mirror of
https://github.com/davidhalter/typeshed.git
synced 2026-01-24 03:51:52 +08:00
Use _typeshed.Self in Python 2, too (#6932)
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import types
|
||||
from _typeshed import Self
|
||||
from abc import abstractmethod
|
||||
from typing import (
|
||||
IO,
|
||||
@@ -14,7 +15,6 @@ from typing import (
|
||||
TextIO,
|
||||
Tuple,
|
||||
Type,
|
||||
TypeVar,
|
||||
Union,
|
||||
overload,
|
||||
)
|
||||
@@ -189,8 +189,6 @@ class BufferedIncrementalDecoder(IncrementalDecoder):
|
||||
def _buffer_decode(self, input: _Encoded, errors: str, final: bool) -> Tuple[_Decoded, int]: ...
|
||||
def decode(self, input: _Encoded, final: bool = ...) -> _Decoded: ...
|
||||
|
||||
_SW = TypeVar("_SW", bound=StreamWriter)
|
||||
|
||||
# TODO: it is not possible to specify the requirement that all other
|
||||
# attributes and methods are passed-through from the stream.
|
||||
class StreamWriter(Codec):
|
||||
@@ -199,12 +197,10 @@ class StreamWriter(Codec):
|
||||
def write(self, object: _Decoded) -> None: ...
|
||||
def writelines(self, list: Iterable[_Decoded]) -> None: ...
|
||||
def reset(self) -> None: ...
|
||||
def __enter__(self: _SW) -> _SW: ...
|
||||
def __enter__(self: Self) -> Self: ...
|
||||
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: ...
|
||||
|
||||
_SR = TypeVar("_SR", bound=StreamReader)
|
||||
|
||||
class StreamReader(Codec):
|
||||
errors: str
|
||||
def __init__(self, stream: IO[_Encoded], errors: str = ...) -> None: ...
|
||||
@@ -212,13 +208,11 @@ class StreamReader(Codec):
|
||||
def readline(self, size: int | None = ..., keepends: bool = ...) -> _Decoded: ...
|
||||
def readlines(self, sizehint: int | None = ..., keepends: bool = ...) -> List[_Decoded]: ...
|
||||
def reset(self) -> None: ...
|
||||
def __enter__(self: _SR) -> _SR: ...
|
||||
def __enter__(self: Self) -> Self: ...
|
||||
def __exit__(self, typ: Type[BaseException] | None, exc: BaseException | None, tb: types.TracebackType | None) -> None: ...
|
||||
def __iter__(self) -> Iterator[_Decoded]: ...
|
||||
def __getattr__(self, name: str, getattr: Callable[[str], Any] = ...) -> Any: ...
|
||||
|
||||
_T = TypeVar("_T", bound=StreamReaderWriter)
|
||||
|
||||
# Doesn't actually inherit from TextIO, but wraps a BinaryIO to provide text reading and writing
|
||||
# and delegates attributes to the underlying binary stream with __getattr__.
|
||||
class StreamReaderWriter(TextIO):
|
||||
@@ -227,14 +221,14 @@ class StreamReaderWriter(TextIO):
|
||||
def readline(self, size: int | None = ...) -> _Decoded: ...
|
||||
def readlines(self, sizehint: int | None = ...) -> List[_Decoded]: ...
|
||||
def next(self) -> Text: ...
|
||||
def __iter__(self: _T) -> _T: ...
|
||||
def __iter__(self: Self) -> Self: ...
|
||||
# This actually returns None, but that's incompatible with the supertype
|
||||
def write(self, data: _Decoded) -> int: ...
|
||||
def writelines(self, list: Iterable[_Decoded]) -> None: ...
|
||||
def reset(self) -> None: ...
|
||||
# Same as write()
|
||||
def seek(self, offset: int, whence: int = ...) -> int: ...
|
||||
def __enter__(self: _T) -> _T: ...
|
||||
def __enter__(self: Self) -> Self: ...
|
||||
def __exit__(self, typ: Type[BaseException] | None, exc: BaseException | None, tb: types.TracebackType | None) -> None: ...
|
||||
def __getattr__(self, name: str) -> Any: ...
|
||||
# These methods don't actually exist directly, but they are needed to satisfy the TextIO
|
||||
@@ -249,8 +243,6 @@ class StreamReaderWriter(TextIO):
|
||||
def tell(self) -> int: ...
|
||||
def writable(self) -> bool: ...
|
||||
|
||||
_SRT = TypeVar("_SRT", bound=StreamRecoder)
|
||||
|
||||
class StreamRecoder(BinaryIO):
|
||||
def __init__(
|
||||
self,
|
||||
@@ -265,12 +257,12 @@ class StreamRecoder(BinaryIO):
|
||||
def readline(self, size: int | None = ...) -> bytes: ...
|
||||
def readlines(self, sizehint: int | None = ...) -> List[bytes]: ...
|
||||
def next(self) -> bytes: ...
|
||||
def __iter__(self: _SRT) -> _SRT: ...
|
||||
def __iter__(self: Self) -> Self: ...
|
||||
def write(self, data: bytes) -> int: ...
|
||||
def writelines(self, list: Iterable[bytes]) -> int: ... # type: ignore # it's supposed to return None
|
||||
def reset(self) -> None: ...
|
||||
def __getattr__(self, name: str) -> Any: ...
|
||||
def __enter__(self: _SRT) -> _SRT: ...
|
||||
def __enter__(self: Self) -> Self: ...
|
||||
def __exit__(self, type: Type[BaseException] | None, value: BaseException | None, tb: types.TracebackType | None) -> None: ...
|
||||
# These methods don't actually exist directly, but they are needed to satisfy the BinaryIO
|
||||
# interface. At runtime, they are delegated through __getattr__.
|
||||
|
||||
Reference in New Issue
Block a user