|
1 | 1 | import abc
|
2 | 2 | import sys
|
3 | 3 | from _typeshed import FileDescriptorOrPath, Unused
|
4 |
| -from abc import abstractmethod |
| 4 | +from abc import ABC, abstractmethod |
5 | 5 | from collections.abc import AsyncGenerator, AsyncIterator, Awaitable, Callable, Generator, Iterator
|
6 | 6 | from types import TracebackType
|
7 | 7 | from typing import IO, Any, Generic, Protocol, TypeVar, overload, runtime_checkable
|
@@ -38,16 +38,22 @@ _P = ParamSpec("_P")
|
38 | 38 | _ExitFunc: TypeAlias = Callable[[type[BaseException] | None, BaseException | None, TracebackType | None], bool | None]
|
39 | 39 | _CM_EF = TypeVar("_CM_EF", bound=AbstractContextManager[Any, Any] | _ExitFunc)
|
40 | 40 |
|
| 41 | +# mypy and pyright object to this being both ABC and Protocol. |
| 42 | +# At runtime it inherits from ABC and is not a Protocol, but it is on the |
| 43 | +# allowlist for use as a Protocol. |
41 | 44 | @runtime_checkable
|
42 |
| -class AbstractContextManager(Protocol[_T_co, _ExitT_co]): |
| 45 | +class AbstractContextManager(ABC, Protocol[_T_co, _ExitT_co]): # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] |
43 | 46 | def __enter__(self) -> _T_co: ...
|
44 | 47 | @abstractmethod
|
45 | 48 | def __exit__(
|
46 | 49 | self, exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: TracebackType | None, /
|
47 | 50 | ) -> _ExitT_co: ...
|
48 | 51 |
|
| 52 | +# mypy and pyright object to this being both ABC and Protocol. |
| 53 | +# At runtime it inherits from ABC and is not a Protocol, but it is on the |
| 54 | +# allowlist for use as a Protocol. |
49 | 55 | @runtime_checkable
|
50 |
| -class AbstractAsyncContextManager(Protocol[_T_co, _ExitT_co]): |
| 56 | +class AbstractAsyncContextManager(ABC, Protocol[_T_co, _ExitT_co]): # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] |
51 | 57 | async def __aenter__(self) -> _T_co: ...
|
52 | 58 | @abstractmethod
|
53 | 59 | async def __aexit__(
|
|
0 commit comments