classification
Title: traceback.{print_exc,print_exception,format_exc,format_exception}: Potential AttributeError
Type: behavior Stage: resolved
Components: Versions: Python 3.4, Python 3.5
process
Status: closed Resolution: out of date
Dependencies: Superseder: traceback: add a new thin class storing a traceback without storing local variables
View: 17911
Assigned To: georg.brandl Nosy List: Arfrever, berker.peksag, georg.brandl, jedwards1211, r.david.murray
Priority: normal Keywords: patch

Created on 2014-12-06 23:37 by Arfrever, last changed 2016-05-03 20:49 by jedwards1211. This issue is now closed.

Files
File name Uploaded Description Edit
issue23003.diff berker.peksag, 2014-12-07 14:07 review
Messages (3)
msg232259 - (view) Author: Arfrever Frehtes Taifersar Arahesis (Arfrever) * (Python triager) Date: 2014-12-06 23:37
Usage of some functions from traceback module can result in AttributeError exception in Python 3, while simply printing/returning something with None in Python 2.
This regression was introduced in Python 3.0.

$ python2.7 -c 'import traceback; print(traceback.print_exc())'
None
None
$ python2.7 -c 'import traceback; print(traceback.print_exception(None, None, None))'
None
None
$ python2.7 -c 'import traceback; print(traceback.format_exc())'
None

$ python2.7 -c 'import traceback; print(traceback.format_exception(None, None, None))'
['None\n']



$ python3.5 -c 'import traceback; print(traceback.print_exc())'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib64/python3.5/traceback.py", line 252, in print_exc
    print_exception(*sys.exc_info(), limit=limit, file=file, chain=chain)
  File "/usr/lib64/python3.5/traceback.py", line 169, in print_exception
    for line in _format_exception_iter(etype, value, tb, limit, chain):
  File "/usr/lib64/python3.5/traceback.py", line 146, in _format_exception_iter
    for value, tb in values:
  File "/usr/lib64/python3.5/traceback.py", line 125, in _iter_chain
    context = exc.__context__
AttributeError: 'NoneType' object has no attribute '__context__'
$ python3.5 -c 'import traceback; print(traceback.print_exception(None, None, None))'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib64/python3.5/traceback.py", line 169, in print_exception
    for line in _format_exception_iter(etype, value, tb, limit, chain):
  File "/usr/lib64/python3.5/traceback.py", line 146, in _format_exception_iter
    for value, tb in values:
  File "/usr/lib64/python3.5/traceback.py", line 125, in _iter_chain
    context = exc.__context__
AttributeError: 'NoneType' object has no attribute '__context__'
$ python3.5 -c 'import traceback; print(traceback.format_exc())'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib64/python3.5/traceback.py", line 256, in format_exc
    return "".join(format_exception(*sys.exc_info(), limit=limit, chain=chain))
  File "/usr/lib64/python3.5/traceback.py", line 181, in format_exception
    return list(_format_exception_iter(etype, value, tb, limit, chain))
  File "/usr/lib64/python3.5/traceback.py", line 146, in _format_exception_iter
    for value, tb in values:
  File "/usr/lib64/python3.5/traceback.py", line 125, in _iter_chain
    context = exc.__context__
AttributeError: 'NoneType' object has no attribute '__context__'
$ python3.5 -c 'import traceback; print(traceback.format_exception(None, None, None))'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib64/python3.5/traceback.py", line 181, in format_exception
    return list(_format_exception_iter(etype, value, tb, limit, chain))
  File "/usr/lib64/python3.5/traceback.py", line 146, in _format_exception_iter
    for value, tb in values:
  File "/usr/lib64/python3.5/traceback.py", line 125, in _iter_chain
    context = exc.__context__
AttributeError: 'NoneType' object has no attribute '__context__'
msg237522 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2015-03-08 09:07
This is no longer an issue after issue 17911.
msg264766 - (view) Author: Andy Edwards (jedwards1211) Date: 2016-05-03 20:49
I'm seeing this issue in Python 2.7....

Andys-MacBook-Pro:jcore-api-py andy$ which python
/Library/Frameworks/Python.framework/Versions/2.7/bin/python
Andys-MacBook-Pro:jcore-api-py andy$ python setup.py test
running test
running egg_info
writing requirements to jcore_api.egg-info/requires.txt
writing jcore_api.egg-info/PKG-INFO
writing top-level names to jcore_api.egg-info/top_level.txt
writing dependency_links to jcore_api.egg-info/dependency_links.txt
reading manifest file 'jcore_api.egg-info/SOURCES.txt'
writing manifest file 'jcore_api.egg-info/SOURCES.txt'
running build_ext
.....................
----------------------------------------------------------------------
Ran 21 tests in 3.423s

OK
Andys-MacBook-Pro:jcore-api-py andy$ python setup.py test
running test
running egg_info
writing requirements to jcore_api.egg-info/requires.txt
writing jcore_api.egg-info/PKG-INFO
writing top-level names to jcore_api.egg-info/top_level.txt
writing dependency_links to jcore_api.egg-info/dependency_links.txt
reading manifest file 'jcore_api.egg-info/SOURCES.txt'
writing manifest file 'jcore_api.egg-info/SOURCES.txt'
running build_ext
.....................
----------------------------------------------------------------------
Ran 21 tests in 3.422s

OK
Exception in thread jcore.io receiver:
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 801, in __bootstrap_inner
    self.run()
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 754, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/Users/andy/jcore-api-py/jcore_api/_connection.py", line 104, in _run_recv_thread
    traceback.print_exc()
AttributeError: 'NoneType' object has no attribute 'print_exc'
History
Date User Action Args
2016-05-03 20:49:45jedwards1211setnosy: + jedwards1211
messages: + msg264766
2015-08-17 15:50:12vstinnersetsuperseder: traceback: add a new thin class storing a traceback without storing local variables
2015-03-08 09:07:35berker.peksagsetstatus: open -> closed
resolution: out of date
messages: + msg237522

stage: patch review -> resolved
2014-12-07 16:02:33r.david.murraysetnosy: + r.david.murray
2014-12-07 14:07:05berker.peksagsetfiles: + issue23003.diff

nosy: + berker.peksag
keywords: + patch
type: behavior
stage: patch review
2014-12-06 23:44:58Arfreversetassignee: georg.brandl

nosy: + georg.brandl
2014-12-06 23:37:27Arfrevercreate