Skip to content

Commit 947724a

Browse files
authored
stdlib: Add several missing @abstractmethod decorators (#7443)
1 parent 2fb9c35 commit 947724a

File tree

7 files changed

+29
-4
lines changed

7 files changed

+29
-4
lines changed

stdlib/contextlib.pyi

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ elif sys.version_info >= (3, 7):
137137
func: Callable[..., AsyncGenerator[_T_co, Any]]
138138
args: tuple[Any, ...]
139139
kwds: dict[str, Any]
140+
async def __aexit__(
141+
self, typ: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None
142+
) -> bool | None: ...
140143

141144
if sys.version_info >= (3, 7):
142145
def asynccontextmanager(func: Callable[_P, AsyncIterator[_T_co]]) -> Callable[_P, _AsyncGeneratorContextManager[_T_co]]: ...
@@ -148,6 +151,7 @@ _SupportsCloseT = TypeVar("_SupportsCloseT", bound=_SupportsClose)
148151

149152
class closing(AbstractContextManager[_SupportsCloseT]):
150153
def __init__(self, thing: _SupportsCloseT) -> None: ...
154+
def __exit__(self, *exc_info: object) -> None: ...
151155

152156
if sys.version_info >= (3, 10):
153157
class _SupportsAclose(Protocol):
@@ -156,18 +160,22 @@ if sys.version_info >= (3, 10):
156160

157161
class aclosing(AbstractAsyncContextManager[_SupportsAcloseT]):
158162
def __init__(self, thing: _SupportsAcloseT) -> None: ...
163+
async def __aexit__(self, *exc_info: object) -> None: ...
159164

160165
class suppress(AbstractContextManager[None]):
161166
def __init__(self, *exceptions: type[BaseException]) -> None: ...
162167
def __exit__(
163168
self, exctype: type[BaseException] | None, excinst: BaseException | None, exctb: TracebackType | None
164169
) -> bool: ...
165170

166-
class redirect_stdout(AbstractContextManager[_T_io]):
171+
class _RedirectStream(AbstractContextManager[_T_io]):
167172
def __init__(self, new_target: _T_io) -> None: ...
173+
def __exit__(
174+
self, exctype: type[BaseException] | None, excinst: BaseException | None, exctb: TracebackType | None
175+
) -> None: ...
168176

169-
class redirect_stderr(AbstractContextManager[_T_io]):
170-
def __init__(self, new_target: _T_io) -> None: ...
177+
class redirect_stdout(_RedirectStream[_T_io]): ...
178+
class redirect_stderr(_RedirectStream[_T_io]): ...
171179

172180
class ExitStack(AbstractContextManager[ExitStack]):
173181
def __init__(self) -> None: ...

stdlib/mmap.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ class mmap(AbstractContextManager[mmap], Iterable[int], Sized):
7070
# Doesn't actually exist, but the object is actually iterable because it has __getitem__ and
7171
# __len__, so we claim that there is also an __iter__ to help type checkers.
7272
def __iter__(self) -> Iterator[int]: ...
73+
def __exit__(self, *args: object) -> None: ...
7374

7475
if sys.version_info >= (3, 8) and sys.platform != "win32":
7576
MADV_NORMAL: int

stdlib/multiprocessing/synchronize.pyi

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import sys
22
import threading
33
from contextlib import AbstractContextManager
44
from multiprocessing.context import BaseContext
5+
from types import TracebackType
56
from typing import Any, Callable, Union
67

78
__all__ = ["Lock", "RLock", "Semaphore", "BoundedSemaphore", "Condition", "Event"]
@@ -28,8 +29,11 @@ class Condition(AbstractContextManager[bool]):
2829
def wait_for(self, predicate: Callable[[], bool], timeout: float | None = ...) -> bool: ...
2930
def acquire(self, block: bool = ..., timeout: float | None = ...) -> bool: ...
3031
def release(self) -> None: ...
32+
def __exit__(
33+
self, __exc_type: type[BaseException] | None, __exc_val: BaseException | None, __exc_tb: TracebackType | None
34+
) -> None: ...
3135

32-
class Event(AbstractContextManager[bool]):
36+
class Event:
3337
def __init__(self, lock: _LockLike | None = ..., *, ctx: BaseContext) -> None: ...
3438
def is_set(self) -> bool: ...
3539
def set(self) -> None: ...
@@ -49,3 +53,6 @@ class Semaphore(SemLock):
4953
class SemLock(AbstractContextManager[bool]):
5054
def acquire(self, block: bool = ..., timeout: float | None = ...) -> bool: ...
5155
def release(self) -> None: ...
56+
def __exit__(
57+
self, __exc_type: type[BaseException] | None, __exc_val: BaseException | None, __exc_tb: TracebackType | None
58+
) -> None: ...

stdlib/numbers.pyi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,11 @@ class Complex(Number):
4242
def __pow__(self, exponent: Any) -> Any: ...
4343
@abstractmethod
4444
def __rpow__(self, base: Any) -> Any: ...
45+
@abstractmethod
4546
def __abs__(self) -> Real: ...
47+
@abstractmethod
4648
def conjugate(self) -> Any: ...
49+
@abstractmethod
4750
def __eq__(self, other: object) -> bool: ...
4851

4952
class Real(Complex, SupportsFloat):

stdlib/os/__init__.pyi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ from _typeshed import (
1212
StrPath,
1313
structseq,
1414
)
15+
from abc import abstractmethod
1516
from builtins import OSError
1617
from contextlib import AbstractContextManager
1718
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
371372

372373
@runtime_checkable
373374
class PathLike(Protocol[_AnyStr_co]):
375+
@abstractmethod
374376
def __fspath__(self) -> _AnyStr_co: ...
375377

376378
@overload
@@ -728,6 +730,7 @@ def rmdir(path: StrOrBytesPath, *, dir_fd: int | None = ...) -> None: ...
728730

729731
class _ScandirIterator(Iterator[DirEntry[AnyStr]], AbstractContextManager[_ScandirIterator[AnyStr]]):
730732
def __next__(self) -> DirEntry[AnyStr]: ...
733+
def __exit__(self, *args: object) -> None: ...
731734
def close(self) -> None: ...
732735

733736
if sys.version_info >= (3, 7):

stdlib/pathlib.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class PurePath(PathLike[str]):
3939
def __new__(cls: type[Self], *args: StrPath) -> Self: ...
4040
def __hash__(self) -> int: ...
4141
def __eq__(self, other: object) -> bool: ...
42+
def __fspath__(self) -> str: ...
4243
def __lt__(self, other: PurePath) -> bool: ...
4344
def __le__(self, other: PurePath) -> bool: ...
4445
def __gt__(self, other: PurePath) -> bool: ...

stdlib/typing.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -902,13 +902,15 @@ class ValuesView(MappingView, Iterable[_VT_co], Generic[_VT_co]):
902902
@runtime_checkable
903903
class ContextManager(Protocol[_T_co]):
904904
def __enter__(self) -> _T_co: ...
905+
@abstractmethod
905906
def __exit__(
906907
self, __exc_type: Type[BaseException] | None, __exc_value: BaseException | None, __traceback: TracebackType | None
907908
) -> bool | None: ...
908909

909910
@runtime_checkable
910911
class AsyncContextManager(Protocol[_T_co]):
911912
async def __aenter__(self) -> _T_co: ...
913+
@abstractmethod
912914
async def __aexit__(
913915
self, __exc_type: Type[BaseException] | None, __exc_value: BaseException | None, __traceback: TracebackType | None
914916
) -> bool | None: ...

0 commit comments

Comments
 (0)