mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-07 12:44:28 +08:00
Use _typeshed.Self with __enter__ (#5717)
Co-authored-by: Akuli <akuviljanen17@gmail.com>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import io
|
||||
from _typeshed import ReadableBuffer, StrOrBytesPath
|
||||
from typing import IO, Any, Mapping, Optional, Sequence, TextIO, TypeVar, Union, overload
|
||||
from _typeshed import ReadableBuffer, Self, StrOrBytesPath
|
||||
from typing import IO, Any, Mapping, Optional, Sequence, TextIO, Union, overload
|
||||
from typing_extensions import Literal
|
||||
|
||||
_OpenBinaryWritingMode = Literal["w", "wb", "x", "xb", "a", "ab"]
|
||||
@@ -9,7 +9,6 @@ _OpenTextWritingMode = Literal["wt", "xt", "at"]
|
||||
_PathOrFile = Union[StrOrBytesPath, IO[bytes]]
|
||||
|
||||
_FilterChain = Sequence[Mapping[str, Any]]
|
||||
_T = TypeVar("_T")
|
||||
|
||||
FORMAT_AUTO: int
|
||||
FORMAT_XZ: int
|
||||
@@ -76,7 +75,7 @@ class LZMAFile(io.BufferedIOBase, IO[bytes]):
|
||||
preset: Optional[int] = ...,
|
||||
filters: Optional[_FilterChain] = ...,
|
||||
) -> None: ...
|
||||
def __enter__(self: _T) -> _T: ...
|
||||
def __enter__(self: Self) -> Self: ...
|
||||
def close(self) -> None: ...
|
||||
@property
|
||||
def closed(self) -> bool: ...
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import email.message
|
||||
import sys
|
||||
from _typeshed import StrOrBytesPath
|
||||
from _typeshed import Self, StrOrBytesPath
|
||||
from types import TracebackType
|
||||
from typing import (
|
||||
IO,
|
||||
@@ -189,7 +189,7 @@ class _ProxyFile(Generic[AnyStr]):
|
||||
def tell(self) -> int: ...
|
||||
def seek(self, offset: int, whence: int = ...) -> None: ...
|
||||
def close(self) -> None: ...
|
||||
def __enter__(self) -> _ProxyFile[AnyStr]: ...
|
||||
def __enter__(self: Self) -> Self: ...
|
||||
def __exit__(
|
||||
self, exc_type: Optional[Type[BaseException]], exc: Optional[BaseException], tb: Optional[TracebackType]
|
||||
) -> None: ...
|
||||
|
||||
@@ -2,9 +2,9 @@ import datetime
|
||||
import socket
|
||||
import ssl
|
||||
import sys
|
||||
from typing import IO, Any, Dict, Iterable, List, NamedTuple, Optional, Tuple, TypeVar, Union
|
||||
from _typeshed import Self
|
||||
from typing import IO, Any, Dict, Iterable, List, NamedTuple, Optional, Tuple, Union
|
||||
|
||||
_SelfT = TypeVar("_SelfT", bound=_NNTPBase)
|
||||
_File = Union[IO[bytes], bytes, str, None]
|
||||
|
||||
class NNTPError(Exception):
|
||||
@@ -46,7 +46,7 @@ class _NNTPBase:
|
||||
nntp_implementation: str
|
||||
nntp_version: int
|
||||
def __init__(self, file: IO[bytes], host: str, readermode: Optional[bool] = ..., timeout: float = ...) -> None: ...
|
||||
def __enter__(self: _SelfT) -> _SelfT: ...
|
||||
def __enter__(self: Self) -> Self: ...
|
||||
def __exit__(self, *args: Any) -> None: ...
|
||||
def getwelcome(self) -> str: ...
|
||||
def getcapabilities(self) -> Dict[str, List[str]]: ...
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
import sys
|
||||
from _typeshed import OpenBinaryMode, OpenBinaryModeReading, OpenBinaryModeUpdating, OpenBinaryModeWriting, OpenTextMode, StrPath
|
||||
from _typeshed import (
|
||||
OpenBinaryMode,
|
||||
OpenBinaryModeReading,
|
||||
OpenBinaryModeUpdating,
|
||||
OpenBinaryModeWriting,
|
||||
OpenTextMode,
|
||||
Self,
|
||||
StrPath,
|
||||
)
|
||||
from io import BufferedRandom, BufferedReader, BufferedWriter, FileIO, TextIOWrapper
|
||||
from os import PathLike, stat_result
|
||||
from types import TracebackType
|
||||
@@ -54,7 +62,7 @@ class PureWindowsPath(PurePath): ...
|
||||
|
||||
class Path(PurePath):
|
||||
def __new__(cls: Type[_P], *args: StrPath, **kwargs: Any) -> _P: ...
|
||||
def __enter__(self: _P) -> _P: ...
|
||||
def __enter__(self: Self) -> Self: ...
|
||||
def __exit__(
|
||||
self, exc_type: Optional[Type[BaseException]], exc_value: Optional[BaseException], traceback: Optional[TracebackType]
|
||||
) -> Optional[bool]: ...
|
||||
|
||||
@@ -1,19 +1,18 @@
|
||||
from _typeshed import Self
|
||||
from types import ModuleType
|
||||
from typing import Any, Dict, Optional, TypeVar
|
||||
|
||||
_T = TypeVar("_T")
|
||||
from typing import Any, Dict, Optional
|
||||
|
||||
class _TempModule:
|
||||
mod_name: str = ...
|
||||
module: ModuleType = ...
|
||||
def __init__(self, mod_name: str) -> None: ...
|
||||
def __enter__(self: _T) -> _T: ...
|
||||
def __enter__(self: Self) -> Self: ...
|
||||
def __exit__(self, *args: Any) -> None: ...
|
||||
|
||||
class _ModifiedArgv0:
|
||||
value: Any = ...
|
||||
def __init__(self, value: Any) -> None: ...
|
||||
def __enter__(self: _T) -> _T: ...
|
||||
def __enter__(self) -> None: ...
|
||||
def __exit__(self, *args: Any) -> None: ...
|
||||
|
||||
def run_module(
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import sys
|
||||
from _typeshed import FileDescriptorLike
|
||||
from _typeshed import FileDescriptorLike, Self
|
||||
from types import TracebackType
|
||||
from typing import Any, Iterable, List, Optional, Tuple, Type
|
||||
|
||||
@@ -101,7 +101,7 @@ if sys.platform != "linux" and sys.platform != "win32":
|
||||
if sys.platform == "linux":
|
||||
class epoll(object):
|
||||
def __init__(self, sizehint: int = ..., flags: int = ...) -> None: ...
|
||||
def __enter__(self) -> epoll: ...
|
||||
def __enter__(self: Self) -> Self: ...
|
||||
def __exit__(
|
||||
self,
|
||||
exc_type: Optional[Type[BaseException]] = ...,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import sys
|
||||
from _typeshed import FileDescriptor, FileDescriptorLike
|
||||
from _typeshed import FileDescriptor, FileDescriptorLike, Self
|
||||
from abc import ABCMeta, abstractmethod
|
||||
from typing import Any, List, Mapping, NamedTuple, Optional, Tuple
|
||||
|
||||
@@ -26,7 +26,7 @@ class BaseSelector(metaclass=ABCMeta):
|
||||
def get_key(self, fileobj: FileDescriptorLike) -> SelectorKey: ...
|
||||
@abstractmethod
|
||||
def get_map(self) -> Mapping[FileDescriptorLike, SelectorKey]: ...
|
||||
def __enter__(self) -> BaseSelector: ...
|
||||
def __enter__(self: Self) -> Self: ...
|
||||
def __exit__(self, *args: Any) -> None: ...
|
||||
|
||||
class SelectSelector(BaseSelector):
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import sys
|
||||
from _typeshed import ReadableBuffer, WriteableBuffer
|
||||
from _typeshed import ReadableBuffer, Self, WriteableBuffer
|
||||
from collections.abc import Iterable
|
||||
from enum import IntEnum, IntFlag
|
||||
from io import RawIOBase
|
||||
@@ -545,7 +545,7 @@ class socket(_socket.socket):
|
||||
proto: int = ...,
|
||||
fileno: Optional[int] = ...,
|
||||
) -> None: ...
|
||||
def __enter__(self: _T) -> _T: ...
|
||||
def __enter__(self: Self) -> Self: ...
|
||||
def __exit__(self, *args: object) -> None: ...
|
||||
def dup(self: _T) -> _T: ... # noqa: F811
|
||||
def accept(self) -> tuple[socket, _RetAddress]: ...
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import sys
|
||||
import types
|
||||
from _typeshed import Self
|
||||
from socket import socket as _socket
|
||||
from typing import Any, BinaryIO, Callable, ClassVar, Optional, Set, Tuple, Type, TypeVar, Union
|
||||
|
||||
@@ -30,7 +31,7 @@ class BaseServer:
|
||||
def server_activate(self) -> None: ...
|
||||
def server_bind(self) -> None: ...
|
||||
def verify_request(self, request: _RequestType, client_address: _AddressType) -> bool: ...
|
||||
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[types.TracebackType]
|
||||
) -> None: ...
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import sys
|
||||
from _typeshed import StrOrBytesPath
|
||||
from _typeshed import Self, StrOrBytesPath
|
||||
from types import TracebackType
|
||||
from typing import IO, Any, AnyStr, Callable, Generic, Mapping, Optional, Sequence, Tuple, Type, TypeVar, Union, overload
|
||||
from typing_extensions import Literal
|
||||
@@ -34,7 +34,6 @@ if sys.platform == "win32":
|
||||
else:
|
||||
_ENV = Union[Mapping[bytes, StrOrBytesPath], Mapping[str, StrOrBytesPath]]
|
||||
|
||||
_S = TypeVar("_S")
|
||||
_T = TypeVar("_T")
|
||||
|
||||
class CompletedProcess(Generic[_T]):
|
||||
@@ -1007,7 +1006,7 @@ class Popen(Generic[AnyStr]):
|
||||
def send_signal(self, sig: int) -> None: ...
|
||||
def terminate(self) -> None: ...
|
||||
def kill(self) -> None: ...
|
||||
def __enter__(self: _S) -> _S: ...
|
||||
def __enter__(self: Self) -> Self: ...
|
||||
def __exit__(
|
||||
self, type: Optional[Type[BaseException]], value: Optional[BaseException], traceback: Optional[TracebackType]
|
||||
) -> None: ...
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import sys
|
||||
from _typeshed import Self
|
||||
from typing import IO, Any, NamedTuple, NoReturn, Optional, Union
|
||||
|
||||
_File = Union[str, IO[bytes]]
|
||||
@@ -30,7 +31,7 @@ class _sunau_params(NamedTuple):
|
||||
|
||||
class Au_read:
|
||||
def __init__(self, f: _File) -> None: ...
|
||||
def __enter__(self) -> Au_read: ...
|
||||
def __enter__(self: Self) -> Self: ...
|
||||
def __exit__(self, *args: Any) -> None: ...
|
||||
def getfp(self) -> Optional[IO[bytes]]: ...
|
||||
def rewind(self) -> None: ...
|
||||
@@ -50,7 +51,7 @@ class Au_read:
|
||||
|
||||
class Au_write:
|
||||
def __init__(self, f: _File) -> None: ...
|
||||
def __enter__(self) -> Au_write: ...
|
||||
def __enter__(self: Self) -> Self: ...
|
||||
def __exit__(self, *args: Any) -> None: ...
|
||||
def setnchannels(self, nchannels: int) -> None: ...
|
||||
def getnchannels(self) -> int: ...
|
||||
|
||||
Reference in New Issue
Block a user