diff --git a/stdlib/contextlib.pyi b/stdlib/contextlib.pyi index 4795aac67c23..c2731dea7807 100644 --- a/stdlib/contextlib.pyi +++ b/stdlib/contextlib.pyi @@ -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: ... diff --git a/stdlib/mmap.pyi b/stdlib/mmap.pyi index 5dd266e84607..c057ab2f1b2b 100644 --- a/stdlib/mmap.pyi +++ b/stdlib/mmap.pyi @@ -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 diff --git a/stdlib/multiprocessing/synchronize.pyi b/stdlib/multiprocessing/synchronize.pyi index 6764b7666152..cb576abcc815 100644 --- a/stdlib/multiprocessing/synchronize.pyi +++ b/stdlib/multiprocessing/synchronize.pyi @@ -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: ... diff --git a/stdlib/numbers.pyi b/stdlib/numbers.pyi index 7c0c95853741..d94ae7faf890 100644 --- a/stdlib/numbers.pyi +++ b/stdlib/numbers.pyi @@ -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): diff --git a/stdlib/os/__init__.pyi b/stdlib/os/__init__.pyi index d38148e7921f..f59b2de7bc23 100644 --- a/stdlib/os/__init__.pyi +++ b/stdlib/os/__init__.pyi @@ -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 @@ -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): diff --git a/stdlib/pathlib.pyi b/stdlib/pathlib.pyi index fc5d7d8fb7e1..eead11dd310b 100644 --- a/stdlib/pathlib.pyi +++ b/stdlib/pathlib.pyi @@ -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: ... diff --git a/stdlib/typing.pyi b/stdlib/typing.pyi index 08fb6d5b433b..a874a0ddd25c 100644 --- a/stdlib/typing.pyi +++ b/stdlib/typing.pyi @@ -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: ...