[Python-Dev] cpython: Add Py_RETURN_NOTIMPLEMENTED macro. Fixes #12724.
Nick Coghlan
ncoghlan at gmail.com
Tue Aug 16 01:39:09 CEST 2011
On Tue, Aug 16, 2011 at 9:13 AM, Ethan Furman <ethan at stoneleaf.us> wrote:
> Barry Warsaw wrote:
>> So I'd opt for #1, unless we can agree on a better color for the bikeshed.
>
> My apologies if this is just noise, but are there RETURN macros that don't
> do an INCREF?
No, Py_RETURN_NONE is the only previous example, and it was added to
simplify the very common idiom of:
Py_INCREF(Py_None);
return Py_None;
It was added originally because it helped to avoid *two* common bugs:
return Py_None; # segfault waiting to happen
return NULL; # Just plain wrong, but not picked up until tests are
run and hence irritating
I'd say NotImplemented is the second most common instance of that kind
of direct incref-and-return (since operator methods need to return it
to correctly support type coercion), although, as Antoine noted,
Py_True and Py_False would be up there as well.
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
More information about the Python-Dev
mailing list