[Python-Dev] Counting references to Py_None
tim.peters at gmail.com
Sun Mar 20 13:07:47 EDT 2016
[Facundo Batista <facundobatista at gmail.com>]
> I'm seeing that our code increases the reference counting to Py_None,
> and I find this a little strange: isn't Py_None eternal and will never
Yes, but it's immortal in CPython because its reference count never
falls to 0 (it's created with a reference count of 1 to begin with).
That's the only thing that makes it immortal.
> What's the point of counting its references?
Uniformity and simplicity: code using a PyObject* increments and
decrements reference counts appropriately with no concern for what
_kind_ of object is being pointed at. All objects (including None)
are treated exactly the same way for refcount purposes.
More information about the Python-Dev