Created
October 29, 2013 15:45
-
-
Save akaptur/7217177 to your computer and use it in GitHub Desktop.
Possible misunderstanding of how `cause` interacts with context manager silencing in python 3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| >>> class FalseContext(object): | |
| ... def __enter__(self): | |
| ... l.append('i') | |
| ... return self | |
| ... def __exit__(self, exc_type, exc_val, exc_tb): | |
| ... l.append('o') | |
| ... return False | |
| ... | |
| >>> class TrueContext(object): | |
| ... def __enter__(self): | |
| ... l.append('i') | |
| ... return self | |
| ... def __exit__(self, exc_type, exc_val, exc_tb): | |
| ... l.append('o') | |
| ... return True | |
| ... | |
| >>> with TrueContext(): | |
| ... raise Exception | |
| ... | |
| >>> with FalseContext(): | |
| ... raise Exception | |
| ... | |
| Traceback (most recent call last): | |
| File "<stdin>", line 2, in <module> | |
| Exception | |
| >>> with TrueContext(): | |
| ... raise Exception from ValueError | |
| ... | |
| >>> with FalseContext(): | |
| ... raise Exception from ValueError | |
| ... | |
| ValueError | |
| The above exception was the direct cause of the following exception: | |
| Traceback (most recent call last): | |
| File "<stdin>", line 2, in <module> | |
| Exception |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment