Created
November 20, 2014 10:15
-
-
Save romuald/8dc9e53c5c4be9e329d1 to your computer and use it in GitHub Desktop.
python context manager behavior changing over python versions
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
import sys | |
class Bar(object): | |
def __enter__(self): | |
pass | |
def __exit__(self, exc, exc_type, tb): | |
return True | |
with Bar(): | |
raise RuntimeError('foo') | |
# sys.exc_info() returns (None, None, None) under python 2.6, | |
# and the RuntimeError under python 2.7 | |
# ... and (None, None, None) under python 3.x | |
print(sys.exc_info()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment