You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Oddly this only seems to happen when using ExitStack specifically - no other context manager, based on other functions / classes / etc, in my codebase triggers this bug.
The text was updated successfully, but these errors were encountered:
The ExitStack() is annotated in typeshed as something that can swallow exceptions. This kind of matches the docs (if any of the context managers in the stack swallows exceptions).
Of course in this simplified case there is nothing that can raise an exception in the first place. But I assume your code is more complex. I think the best way forward is to just silence it by adding:
assertFalse, "unreachable"
after the context manager.
In principle we can add some special-casing for ExitStack() and/or add a concept of non-raising statements. This may be tricky to add, so I think this is low priority.
Ah, that makes sense, I hadn't considered that behaviour of ExitStack… seems this is working as intended - though maybe the error message from mypy could be improved to explain this better, e.g. "Missing return - the managed context using ExitStack can turn exceptions thrown inside the context into silently jumping to & falling off the end of the context.".
test.py:
mypy complains: test.py:3: error: Missing return statement
Oddly this only seems to happen when using ExitStack specifically - no other context manager, based on other functions / classes / etc, in my codebase triggers this bug.
The text was updated successfully, but these errors were encountered: