New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
contextlib.contextmanager may incorrectly unchain RuntimeError #73878
Comments
As part of PEP-479, an extra check was added to contextlib._GeneratorContextManager to avoid getting confused when a StopIteration exception was raised in the body of the with statement, and hence thrown into the generator body implementing the context manager. This extra check should only be used when the passed in exception is Compare the current contextmanager behaviour:
To the expected inline behaviour:
|
The __exit__() method doesn't conform PEP-8. PEP-8: """Be consistent in return statements. Either all return statements in a function should return an expression, or none of them should. If any return statement returns an expression, any return statements where no value is returned should explicitly state this as return None , and an explicit return statement should be present at the end of the function (if reachable).""" The __exit__() method has explicit "return False", bare "return", and implicit "return" at the end of the method. Together with different styles in different "except" clauses this makes it slightly hard to read. |
PEP-8's rule makes sense elsewhere, but for context managers I think an implicit return None is the norm and that making it explicit wouldn't improve readability. |
Then the exception for the __exit__ method should be documented in PEP-8. |
This has been merged for 3.7, but cherry-picks to the other branches are still needed. I also inadvertently missed adding svelankar's name (Siddharth Velankar) to Misc/ACKS, so that oversight will need to be tidied up as well. |
PR has been backported into 3.5 and 3.6. Thanks all :) |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: