Use _typeshed.Self with __enter__ (#5717)

Co-authored-by: Akuli <akuviljanen17@gmail.com>
This commit is contained in:
Anton Grübel
2021-07-01 12:32:32 +02:00
committed by GitHub
parent 04f0113d16
commit 96e0660fba
12 changed files with 44 additions and 39 deletions

View File

@@ -1,9 +1,9 @@
import builtins
import codecs
import sys
from _typeshed import ReadableBuffer, WriteableBuffer
from _typeshed import ReadableBuffer, Self, WriteableBuffer
from types import TracebackType
from typing import IO, Any, BinaryIO, Callable, Iterable, Iterator, List, Optional, TextIO, Tuple, Type, TypeVar, Union
from typing import IO, Any, BinaryIO, Callable, Iterable, Iterator, List, Optional, TextIO, Tuple, Type, Union
DEFAULT_BUFFER_SIZE: int
@@ -11,8 +11,6 @@ SEEK_SET: int
SEEK_CUR: int
SEEK_END: int
_T = TypeVar("_T", bound=IOBase)
open = builtins.open
if sys.version_info >= (3, 8):
@@ -25,7 +23,7 @@ class UnsupportedOperation(OSError, ValueError): ...
class IOBase:
def __iter__(self) -> Iterator[bytes]: ...
def __next__(self) -> bytes: ...
def __enter__(self: _T) -> _T: ...
def __enter__(self: Self) -> Self: ...
def __exit__(
self, exc_type: Optional[Type[BaseException]], exc_val: Optional[BaseException], exc_tb: Optional[TracebackType]
) -> Optional[bool]: ...
@@ -79,7 +77,7 @@ class FileIO(RawIOBase, BinaryIO):
def closefd(self) -> bool: ...
def write(self, __b: ReadableBuffer) -> int: ...
def read(self, __size: int = ...) -> bytes: ...
def __enter__(self: _T) -> _T: ...
def __enter__(self: Self) -> Self: ...
class BytesIO(BufferedIOBase, BinaryIO):
def __init__(self, initial_bytes: bytes = ...) -> None: ...
@@ -87,7 +85,7 @@ class BytesIO(BufferedIOBase, BinaryIO):
# to allow BytesIO sub-classes to add this field, as it is defined
# as a read-only property on IO[].
name: Any
def __enter__(self: _T) -> _T: ...
def __enter__(self: Self) -> Self: ...
def getvalue(self) -> bytes: ...
def getbuffer(self) -> memoryview: ...
if sys.version_info >= (3, 7):
@@ -96,7 +94,7 @@ class BytesIO(BufferedIOBase, BinaryIO):
def read1(self, __size: Optional[int]) -> bytes: ... # type: ignore
class BufferedReader(BufferedIOBase, BinaryIO):
def __enter__(self: _T) -> _T: ...
def __enter__(self: Self) -> Self: ...
def __init__(self, raw: RawIOBase, buffer_size: int = ...) -> None: ...
def peek(self, __size: int = ...) -> bytes: ...
if sys.version_info >= (3, 7):
@@ -105,12 +103,12 @@ class BufferedReader(BufferedIOBase, BinaryIO):
def read1(self, __size: int) -> bytes: ... # type: ignore
class BufferedWriter(BufferedIOBase, BinaryIO):
def __enter__(self: _T) -> _T: ...
def __enter__(self: Self) -> Self: ...
def __init__(self, raw: RawIOBase, buffer_size: int = ...) -> None: ...
def write(self, __buffer: ReadableBuffer) -> int: ...
class BufferedRandom(BufferedReader, BufferedWriter):
def __enter__(self: _T) -> _T: ...
def __enter__(self: Self) -> Self: ...
def __init__(self, raw: RawIOBase, buffer_size: int = ...) -> None: ...
def seek(self, __target: int, __whence: int = ...) -> int: ...
if sys.version_info >= (3, 7):
@@ -165,7 +163,7 @@ class TextIOWrapper(TextIOBase, TextIO):
write_through: Optional[bool] = ...,
) -> None: ...
# These are inherited from TextIOBase, but must exist in the stub to satisfy mypy.
def __enter__(self: _T) -> _T: ...
def __enter__(self: Self) -> Self: ...
def __iter__(self) -> Iterator[str]: ... # type: ignore
def __next__(self) -> str: ... # type: ignore
def writelines(self, __lines: Iterable[str]) -> None: ... # type: ignore