Last active
December 25, 2015 00:09
-
-
Save satiani/6885627 to your computer and use it in GitHub Desktop.
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 TestContext(object): | |
def __init__(self): | |
self.entered = False | |
self.exited = False | |
def __enter__(self): | |
self.entered = True | |
def __exit__(self, exc_type, exc_value, tb): | |
self.exited = True | |
sys.exc_clear() | |
print "In __exit__", sys.exc_info() | |
c = TestContext() | |
try: | |
with c: | |
raise Exception('dummy') | |
except: | |
pass | |
# prints True | |
print c.entered | |
# prints True | |
print c.exited | |
print "At the end: ", sys.exc_info() | |
# Output: | |
# In __exit__ (None, None, None) | |
# True | |
# True | |
# At the end: (<type 'exceptions.Exception'>, Exception('dummy',), <traceback object at 0x1c053b0>) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment