stdlib: Add several missing @abstractmethod decorators (#7443)

This commit is contained in:
Alex Waygood
2022-03-07 00:41:13 +00:00
committed by GitHub
parent 2fb9c35ff9
commit 947724a5cb
7 changed files with 29 additions and 4 deletions

View File

@@ -137,6 +137,9 @@ elif sys.version_info >= (3, 7):
func: Callable[..., AsyncGenerator[_T_co, Any]]
args: tuple[Any, ...]
kwds: dict[str, Any]
async def __aexit__(
self, typ: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None
) -> bool | None: ...
if sys.version_info >= (3, 7):
def asynccontextmanager(func: Callable[_P, AsyncIterator[_T_co]]) -> Callable[_P, _AsyncGeneratorContextManager[_T_co]]: ...
@@ -148,6 +151,7 @@ _SupportsCloseT = TypeVar("_SupportsCloseT", bound=_SupportsClose)
class closing(AbstractContextManager[_SupportsCloseT]):
def __init__(self, thing: _SupportsCloseT) -> None: ...
def __exit__(self, *exc_info: object) -> None: ...
if sys.version_info >= (3, 10):
class _SupportsAclose(Protocol):
@@ -156,6 +160,7 @@ if sys.version_info >= (3, 10):
class aclosing(AbstractAsyncContextManager[_SupportsAcloseT]):
def __init__(self, thing: _SupportsAcloseT) -> None: ...
async def __aexit__(self, *exc_info: object) -> None: ...
class suppress(AbstractContextManager[None]):
def __init__(self, *exceptions: type[BaseException]) -> None: ...
@@ -163,11 +168,14 @@ class suppress(AbstractContextManager[None]):
self, exctype: type[BaseException] | None, excinst: BaseException | None, exctb: TracebackType | None
) -> bool: ...
class redirect_stdout(AbstractContextManager[_T_io]):
class _RedirectStream(AbstractContextManager[_T_io]):
def __init__(self, new_target: _T_io) -> None: ...
def __exit__(
self, exctype: type[BaseException] | None, excinst: BaseException | None, exctb: TracebackType | None
) -> None: ...
class redirect_stderr(AbstractContextManager[_T_io]):
def __init__(self, new_target: _T_io) -> None: ...
class redirect_stdout(_RedirectStream[_T_io]): ...
class redirect_stderr(_RedirectStream[_T_io]): ...
class ExitStack(AbstractContextManager[ExitStack]):
def __init__(self) -> None: ...

View File

@@ -70,6 +70,7 @@ class mmap(AbstractContextManager[mmap], Iterable[int], Sized):
# Doesn't actually exist, but the object is actually iterable because it has __getitem__ and
# __len__, so we claim that there is also an __iter__ to help type checkers.
def __iter__(self) -> Iterator[int]: ...
def __exit__(self, *args: object) -> None: ...
if sys.version_info >= (3, 8) and sys.platform != "win32":
MADV_NORMAL: int

View File

@@ -2,6 +2,7 @@ import sys
import threading
from contextlib import AbstractContextManager
from multiprocessing.context import BaseContext
from types import TracebackType
from typing import Any, Callable, Union
__all__ = ["Lock", "RLock", "Semaphore", "BoundedSemaphore", "Condition", "Event"]
@@ -28,8 +29,11 @@ class Condition(AbstractContextManager[bool]):
def wait_for(self, predicate: Callable[[], bool], timeout: float | None = ...) -> bool: ...
def acquire(self, block: bool = ..., timeout: float | None = ...) -> bool: ...
def release(self) -> None: ...
def __exit__(
self, __exc_type: type[BaseException] | None, __exc_val: BaseException | None, __exc_tb: TracebackType | None
) -> None: ...
class Event(AbstractContextManager[bool]):
class Event:
def __init__(self, lock: _LockLike | None = ..., *, ctx: BaseContext) -> None: ...
def is_set(self) -> bool: ...
def set(self) -> None: ...
@@ -49,3 +53,6 @@ class Semaphore(SemLock):
class SemLock(AbstractContextManager[bool]):
def acquire(self, block: bool = ..., timeout: float | None = ...) -> bool: ...
def release(self) -> None: ...
def __exit__(
self, __exc_type: type[BaseException] | None, __exc_val: BaseException | None, __exc_tb: TracebackType | None
) -> None: ...

View File

@@ -42,8 +42,11 @@ class Complex(Number):
def __pow__(self, exponent: Any) -> Any: ...
@abstractmethod
def __rpow__(self, base: Any) -> Any: ...
@abstractmethod
def __abs__(self) -> Real: ...
@abstractmethod
def conjugate(self) -> Any: ...
@abstractmethod
def __eq__(self, other: object) -> bool: ...
class Real(Complex, SupportsFloat):

View File

@@ -12,6 +12,7 @@ from _typeshed import (
StrPath,
structseq,
)
from abc import abstractmethod
from builtins import OSError
from contextlib import AbstractContextManager
from io import BufferedRandom, BufferedReader, BufferedWriter, FileIO, TextIOWrapper as _TextIOWrapper
@@ -371,6 +372,7 @@ class stat_result(structseq[float], tuple[int, int, int, int, int, int, int, flo
@runtime_checkable
class PathLike(Protocol[_AnyStr_co]):
@abstractmethod
def __fspath__(self) -> _AnyStr_co: ...
@overload
@@ -728,6 +730,7 @@ def rmdir(path: StrOrBytesPath, *, dir_fd: int | None = ...) -> None: ...
class _ScandirIterator(Iterator[DirEntry[AnyStr]], AbstractContextManager[_ScandirIterator[AnyStr]]):
def __next__(self) -> DirEntry[AnyStr]: ...
def __exit__(self, *args: object) -> None: ...
def close(self) -> None: ...
if sys.version_info >= (3, 7):

View File

@@ -39,6 +39,7 @@ class PurePath(PathLike[str]):
def __new__(cls: type[Self], *args: StrPath) -> Self: ...
def __hash__(self) -> int: ...
def __eq__(self, other: object) -> bool: ...
def __fspath__(self) -> str: ...
def __lt__(self, other: PurePath) -> bool: ...
def __le__(self, other: PurePath) -> bool: ...
def __gt__(self, other: PurePath) -> bool: ...

View File

@@ -902,6 +902,7 @@ class ValuesView(MappingView, Iterable[_VT_co], Generic[_VT_co]):
@runtime_checkable
class ContextManager(Protocol[_T_co]):
def __enter__(self) -> _T_co: ...
@abstractmethod
def __exit__(
self, __exc_type: Type[BaseException] | None, __exc_value: BaseException | None, __traceback: TracebackType | None
) -> bool | None: ...
@@ -909,6 +910,7 @@ class ContextManager(Protocol[_T_co]):
@runtime_checkable
class AsyncContextManager(Protocol[_T_co]):
async def __aenter__(self) -> _T_co: ...
@abstractmethod
async def __aexit__(
self, __exc_type: Type[BaseException] | None, __exc_value: BaseException | None, __traceback: TracebackType | None
) -> bool | None: ...