NULL allowed in PyErr_SetString and friends?

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. Regards Antoine.

On Mon, Aug 12, 2013 at 5:10 AM, Antoine Pitrou <solipsis@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
participants (2)
-
Antoine Pitrou
-
Eli Bendersky