8000 Make AbstractContextManager.__exit__ concrete · python/typeshed@a4daf9e · GitHub
[go: up one dir, main page]

Skip to content
< 8000 script crossorigin="anonymous" type="application/javascript" src="https://github.githubassets.com/assets/vendors-node_modules_github_remote-form_dist_index_js-node_modules_delegated-events_dist_inde-94fd67-99b04cc350b5.js" defer="defer">

Commit a4daf9e

Browse files
committed
Make AbstractContextManager.__exit__ concrete
While __exit__ is decorated with @AbstractMethod in the runtime, it is also implemented. This is because cooperative multiple inheritance induces subclasses to call super in __exit__ to ensure that all parent classes handle their exit behaviour as well. The base class's empty definition makes it so that child classes can blindly call super. Unfortunately, decorating this method with @AbstractMethod fools some type checkers into understandably thinking that calling super will be an error.
1 parent 5286722 commit a4daf9e

File tree

1 file changed

+0
-1
lines changed

1 file changed

+0
-1
lines changed

stdlib/contextlib.pyi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ _CM_EF = TypeVar("_CM_EF", bound=AbstractContextManager[Any] | _ExitFunc)
4040
@runtime_checkable
4141
class AbstractContextManager(Protocol[_T_co]):
4242
def __enter__(self) -> _T_co: ...
43-
@abstractmethod
4443
def __exit__(
4544
self, __exc_type: type[BaseException] | None, __exc_value: BaseException | None, __traceback: TracebackType | None
4645
) -> bool | None: ...

0 commit comments

Comments
 (0)
0