I tried to get confused with context managers and was a bit surprised when running my code with Python 2.6. Indeed, the exc_value parameter seems to be a string instead of an exception.
A bit of code to welcome this problem:
import sys class contextmanager(object): def __enter__(self): pass def __exit__(self, type_, value, traceback): assert (type_ is None) == (value is None) if value is not None: print(type(value)) if __name__ == '__main__': print(sys.version_info) with contextmanager(): __name_
As of Python 2.7:
<type 'exceptions.NameError'>
As of Python 3.2:
sys.version_info(major=3, minor=2, micro=3, releaselevel='final', serial=0) <class 'NameError'> # GOOD Traceback (most recent call last): File "test_conman.py", line 17, in <module> __name_ NameError: name '__name_' is not defined
As of Python 2.6:
(2, 6, 7, 'final', 0) <type 'str'>
I understand that exc_value should always be an exception. Am I doing something wrong? Is there something I misunderstood? Is this a known issue?
References
Josay
source share