-
-
Notifications
You must be signed in to change notification settings - Fork 16.7k
Closed
Description
When a context manager exits without an exceptions the arguments to __exit__ are None, but the annotated type doesn't permit that:
Lines 269 to 272 in 8122973
| def __exit__( | |
| self, exc_type: type, exc_value: BaseException, tb: TracebackType | |
| ) -> None: | |
| self.pop(exc_value) |
I tried to pass the return value of app_context() to ExitStack.enter_context() and got this message from the Pyright type checker:
error: Argument of type "AppContext" cannot be assigned to parameter "cm" of type "AbstractContextManager" in function "enter_context"
"AppContext" is incompatible with protocol "AbstractContextManager"
"__exit__" is an incompatible type
Type "(exc_type: type, exc_value: BaseException, tb: TracebackType) -> None" cannot be assigned to type "(__exc_type: Type[BaseException] | None, __exc_value: BaseException | None, __traceback: TracebackType | None) -> bool | None"
Parameter 1: type "Type[BaseException] | None" cannot be assigned to type "type"
Type "Type[BaseException] | None" cannot be assigned to type "type"
Parameter 2: type "BaseException | None" cannot be assigned to type "BaseException"
Type "BaseException | None" cannot be assigned to type "BaseException"
Parameter 3: type "TracebackType | None" cannot be assigned to type "TracebackType" (reportGeneralTypeIssues)
Environment:
Python 3.9.5
Flask 2.0.1
Werkzeug 2.0.1