Message152216
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 |
|
Date |
User |
Action |
Args |
2012-01-29 08:04:33 | ncoghlan | set | recipients:
+ ncoghlan, rhettinger, pitrou, draghuram, aronacher, ezio.melotti, eric.araujo, mrabarnett, steven.daprano, poke, ethan.furman, catalin.iacob |
2012-01-29 08:04:33 | ncoghlan | set | messageid: <1327824273.13.0.407851383654.issue6210@psf.upfronthosting.co.za> |
2012-01-29 08:04:32 | ncoghlan | link | issue6210 messages |
2012-01-29 08:04:31 | ncoghlan | create | |
|