Skip to content

stdlib: Add several missing @abstractmethod decorators #7443

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Mar 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions stdlib/contextlib.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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]]: ...
Expand All @@ -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):
Expand All @@ -156,18 +160,22 @@ 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: ...
def __exit__(
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: ...
Expand Down
1 change: 1 addition & 0 deletions stdlib/mmap.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion stdlib/multiprocessing/synchronize.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -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]):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class doesn't seem to be a context manager at runtime, and doesn't seem to have ever been a context manager at runtime.

class Event:
def __init__(self, lock: _LockLike | None = ..., *, ctx: BaseContext) -> None: ...
def is_set(self) -> bool: ...
def set(self) -> None: ...
Expand All @@ -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: ...
3 changes: 3 additions & 0 deletions stdlib/numbers.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
3 changes: 3 additions & 0 deletions stdlib/os/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -722,6 +724,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):
Expand Down
1 change: 1 addition & 0 deletions stdlib/pathlib.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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: ...
Expand Down
2 changes: 2 additions & 0 deletions stdlib/typing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -902,13 +902,15 @@ 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: ...

@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: ...
Expand Down