Skip to content

Instantly share code, notes, and snippets.

@romuald
Created November 20, 2014 10:15
Show Gist options
  • Save romuald/8dc9e53c5c4be9e329d1 to your computer and use it in GitHub Desktop.
Save romuald/8dc9e53c5c4be9e329d1 to your computer and use it in GitHub Desktop.
python context manager behavior changing over python versions
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