Use _typeshed.Self with __enter__ (#5712)

This commit is contained in:
Anton Grübel
2021-06-30 00:19:25 +02:00
committed by GitHub
parent 35cc7491db
commit c38171a0b3
8 changed files with 24 additions and 27 deletions

View File

@@ -1,3 +1,4 @@
from _typeshed import Self
from mmap import mmap
from typing import IO, Any, BinaryIO, Iterable, List, Optional, Text, TextIO, Tuple, Type, TypeVar, Union
@@ -30,7 +31,7 @@ class _IOBase(BinaryIO):
def tell(self) -> int: ...
def truncate(self, size: Optional[int] = ...) -> int: ...
def writable(self) -> bool: ...
def __enter__(self: _T) -> _T: ...
def __enter__(self: Self) -> Self: ...
def __exit__(
self, t: Optional[Type[BaseException]], value: Optional[BaseException], traceback: Optional[Any]
) -> Optional[bool]: ...
@@ -56,7 +57,7 @@ class _BufferedIOBase(_IOBase):
class BufferedRWPair(_BufferedIOBase):
def __init__(self, reader: _RawIOBase, writer: _RawIOBase, buffer_size: int = ..., max_buffer_size: int = ...) -> None: ...
def peek(self, n: int = ...) -> bytes: ...
def __enter__(self) -> BufferedRWPair: ...
def __enter__(self: Self) -> Self: ...
class BufferedRandom(_BufferedIOBase):
mode: str
@@ -140,7 +141,7 @@ class _TextIOBase(TextIO):
def writable(self) -> bool: ...
def write(self, pbuf: unicode) -> int: ...
def writelines(self, lines: Iterable[unicode]) -> None: ...
def __enter__(self: _T) -> _T: ...
def __enter__(self: Self) -> Self: ...
def __exit__(
self, t: Optional[Type[BaseException]], value: Optional[BaseException], traceback: Optional[Any]
) -> Optional[bool]: ...

View File

@@ -7,6 +7,7 @@ from _typeshed import (
OpenBinaryModeWriting,
OpenTextMode,
ReadableBuffer,
Self,
StrOrBytesPath,
SupportsDivMod,
SupportsKeysAndGetItem,
@@ -648,7 +649,7 @@ class memoryview(Sized, Sequence[int]):
contiguous: bool
nbytes: int
def __init__(self, obj: ReadableBuffer) -> None: ...
def __enter__(self) -> memoryview: ...
def __enter__(self: Self) -> Self: ...
def __exit__(
self, exc_type: Optional[Type[BaseException]], exc_val: Optional[BaseException], exc_tb: Optional[TracebackType]
) -> None: ...

View File

@@ -1,7 +1,7 @@
import _compression
import sys
from _compression import BaseStream
from _typeshed import ReadableBuffer, StrOrBytesPath, WriteableBuffer
from _typeshed import ReadableBuffer, Self, StrOrBytesPath, WriteableBuffer
from typing import IO, Any, Iterable, List, Optional, Protocol, TextIO, TypeVar, Union, overload
from typing_extensions import Literal, SupportsIndex
@@ -82,7 +82,7 @@ def open(
) -> TextIO: ...
class BZ2File(BaseStream, IO[bytes]):
def __enter__(self: _T) -> _T: ...
def __enter__(self: Self) -> Self: ...
if sys.version_info >= (3, 9):
@overload
def __init__(self, filename: _WritableFileobj, mode: _WriteBinaryMode, *, compresslevel: int = ...) -> None: ...

View File

@@ -1,5 +1,5 @@
import sys
from _typeshed import StrOrBytesPath
from _typeshed import Self, StrOrBytesPath
from types import CodeType
from typing import Any, Callable, Dict, Optional, Tuple, TypeVar, Union
@@ -8,7 +8,6 @@ def runctx(
statement: str, globals: Dict[str, Any], locals: Dict[str, Any], filename: Optional[str] = ..., sort: Union[str, int] = ...
) -> None: ...
_SelfT = TypeVar("_SelfT", bound=Profile)
_T = TypeVar("_T")
_Label = Tuple[str, int, str]
@@ -23,11 +22,11 @@ class Profile:
def dump_stats(self, file: StrOrBytesPath) -> None: ...
def create_stats(self) -> None: ...
def snapshot_stats(self) -> None: ...
def run(self: _SelfT, cmd: str) -> _SelfT: ...
def runctx(self: _SelfT, cmd: str, globals: Dict[str, Any], locals: Dict[str, Any]) -> _SelfT: ...
def run(self: Self, cmd: str) -> Self: ...
def runctx(self: Self, cmd: str, globals: Dict[str, Any], locals: Dict[str, Any]) -> Self: ...
def runcall(self, __func: Callable[..., _T], *args: Any, **kw: Any) -> _T: ...
if sys.version_info >= (3, 8):
def __enter__(self: _SelfT) -> _SelfT: ...
def __enter__(self: Self) -> Self: ...
def __exit__(self, *exc_info: Any) -> None: ...
def label(code: Union[str, CodeType]) -> _Label: ... # undocumented

View File

@@ -1,5 +1,6 @@
import sys
import types
from _typeshed import Self
from abc import abstractmethod
from typing import (
IO,
@@ -188,8 +189,6 @@ class BufferedIncrementalDecoder(IncrementalDecoder):
def _buffer_decode(self, input: bytes, errors: str, final: bool) -> Tuple[str, int]: ...
def decode(self, input: bytes, final: bool = ...) -> str: ...
_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):
@@ -198,14 +197,12 @@ class StreamWriter(Codec):
def write(self, object: str) -> None: ...
def writelines(self, list: Iterable[str]) -> None: ...
def reset(self) -> None: ...
def __enter__(self: _SW) -> _SW: ...
def __enter__(self: Self) -> Self: ...
def __exit__(
self, typ: Optional[Type[BaseException]], exc: Optional[BaseException], tb: Optional[types.TracebackType]
) -> 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[bytes], errors: str = ...) -> None: ...
@@ -213,7 +210,7 @@ class StreamReader(Codec):
def readline(self, size: Optional[int] = ..., keepends: bool = ...) -> str: ...
def readlines(self, sizehint: Optional[int] = ..., keepends: bool = ...) -> List[str]: ...
def reset(self) -> None: ...
def __enter__(self: _SR) -> _SR: ...
def __enter__(self: Self) -> Self: ...
def __exit__(
self, typ: Optional[Type[BaseException]], exc: Optional[BaseException], tb: Optional[types.TracebackType]
) -> None: ...
@@ -237,7 +234,7 @@ class StreamReaderWriter(TextIO):
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: Optional[Type[BaseException]], exc: Optional[BaseException], tb: Optional[types.TracebackType]
) -> None: ...
@@ -275,7 +272,7 @@ class StreamRecoder(BinaryIO):
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: Optional[Type[BaseException]], value: Optional[BaseException], tb: Optional[types.TracebackType]
) -> None: ...

View File

@@ -1,4 +1,5 @@
import sys
from _typeshed import Self
from types import TracebackType
from typing import (
IO,
@@ -80,7 +81,7 @@ class ExitStack(ContextManager[ExitStack]):
def callback(self, callback: Callable[..., Any], *args: Any, **kwds: Any) -> Callable[..., Any]: ...
def pop_all(self: _U) -> _U: ...
def close(self) -> None: ...
def __enter__(self: _U) -> _U: ...
def __enter__(self: Self) -> Self: ...
def __exit__(
self,
__exc_type: Optional[Type[BaseException]],

View File

@@ -1,5 +1,5 @@
import sys
from _typeshed import StrOrBytesPath
from _typeshed import Self, StrOrBytesPath
from typing import IO, Any, AnyStr, Callable, Generic, Iterable, Iterator, Union
if sys.version_info >= (3, 10):
@@ -78,7 +78,7 @@ class FileInput(Iterable[AnyStr], Generic[AnyStr]):
) -> None: ...
def __del__(self) -> None: ...
def close(self) -> None: ...
def __enter__(self) -> FileInput[AnyStr]: ...
def __enter__(self: Self) -> Self: ...
def __exit__(self, type: Any, value: Any, traceback: Any) -> None: ...
def __iter__(self) -> Iterator[AnyStr]: ...
def __next__(self) -> AnyStr: ...

View File

@@ -1,12 +1,10 @@
from _typeshed import SupportsRead, SupportsReadline
from _typeshed import Self, SupportsRead, SupportsReadline
from socket import socket
from ssl import SSLContext
from types import TracebackType
from typing import Any, Callable, Dict, Iterable, Iterator, List, Optional, TextIO, Tuple, Type, TypeVar, Union
from typing import Any, Callable, Dict, Iterable, Iterator, List, Optional, TextIO, Tuple, Type, Union
from typing_extensions import Literal
_T = TypeVar("_T")
MSG_OOB: int
FTP_PORT: int
MAXLINE: int
@@ -34,7 +32,7 @@ class FTP:
lastresp: str
file: Optional[TextIO]
encoding: str
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]
) -> None: ...