[Python-Dev] NULL allowed in PyErr_SetString and friends?
Eli Bendersky
eliben at gmail.com
Mon Aug 12 15:01:57 CEST 2013
On Mon, Aug 12, 2013 at 5:10 AM, Antoine Pitrou <solipsis at pitrou.net> wrote:
>
> Hello,
>
> It seems NULL is allowed as the first argument of PyErr_Format,
> PyErr_SetString and PyErr_SetObject. Moreover, it means "clear the
> error indicator". However, this is not mentioned in the docs. I was
> wondering if we should officialize this behaviour or change it.
>
Since the same capability is available much more clearly through
PyError_Clear (and also through PyError_Restore(NULL, NULL, NULL)), IMHO we
should at least:
1. Document that NULL is not allowed in PyErr_Set{Object|String}
2. Switch all actual uses of that idiom in the stdlib to PyError_Clear
If we don't fear external code breakaga that relies on this undocumented
behavior, we can also add explicit treating of NULL in
PyErr_Set{Object|String} (maybe even asserting). Otherwise, we can just
keep the behavior as is for now, though make it more correct: to do the
reset it would call PyError_Restore(NULL, value, tb) even though
PyError_Restore documents that all args should be NULL to actually clear
the indicator.
Eli
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20130812/8576c295/attachment.html>
More information about the Python-Dev
mailing list