[issue30097] Command-line option to suppress "from None" for debugging

Martin Panter report at bugs.python.org
Sun May 7 05:29:04 EDT 2017


Martin Panter added the comment:

This proposal would be useful. My use case is for when an API suppresses an external exception context:

>>> import os
>>> try:
...     os.environ["NEW_VARIABLE"] = bug  # Hidden exception
... finally:
...     del os.environ["NEW_VARIABLE"]  # KeyError
... 
Traceback (most recent call last):
  File "<stdin>", line 4, in <module>
  File "/usr/lib/python3.5/os.py", line 699, in __delitem__
    raise KeyError(key) from None
KeyError: 'NEW_VARIABLE'

This feels like a step backwards to Python 2, and enabling the full backtrace would make this easier to analyze:

>>> try:
...     os.environ["NEW_VARIABLE"] = bug  # TypeError
... finally:
...     del dict()["NEW_VARIABLE"]  # KeyError
... 
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "/usr/lib/python3.5/os.py", line 688, in __setitem__
    value = self.encodevalue(value)
  File "/usr/lib/python3.5/os.py", line 756, in encode
    raise TypeError("str expected, not %s" % type(value).__name__)
TypeError: str expected, not object

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 4, in <module>
KeyError: 'NEW_VARIABLE'

----------
nosy: +martin.panter

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue30097>
_______________________________________


More information about the Python-bugs-list mailing list