[issue6210] Exception Chaining missing method for suppressing context
Nick Coghlan
report at bugs.python.org
Sun Jan 29 09:04:33 CET 2012
Nick Coghlan <ncoghlan at gmail.com> added the comment:
Ah, nice idea of bringing the boolean constants into the mix so we don't need to invent a new sentinel value.
However, to preserve the current behaviour that "raise X from Y" is essentially just syntactic sugar for: "_var = X; _var.__cause__ = Y; raise Y", I suggest setting the default value for "__cause__" to "False" (indicating "not set"). Then:
"__cause__ is False" means "no cause set, display context"
"__cause__ is None" means "cause explicitly set to None, suppress context"
Any other value means "display cause"
The default value for cause is controlled by get_cause and set_cause in exceptions.c [1]. The basic idea would be to replace the current usage of Py_None and Py_RETURN_NONE in that code with Py_False and Py_RETURN_FALSE, and then change the criteria for valid causes to "arg != Py_None && !PyExceptionInstance_Check(arg)".
In addition to the files already touched by the patch, Lib/traceback.py [2] and its tests will also require updating.
[1] http://hg.python.org/cpython/file/default/Objects/exceptions.c#l293
[2] http://hg.python.org/cpython/file/default/Lib/traceback.py#l117
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue6210>
_______________________________________
More information about the Python-bugs-list
mailing list