Deprecating reload() ???

Jeff Epler jepler at unpythonic.net
Mon Mar 15 16:38:13 EST 2004


On Mon, Mar 15, 2004 at 01:18:34PM -0700, David MacQuigg wrote:
> Maybe you can save a significant amount of memory by having all the
> *system* modules share a common 'None' object, but when a user
> explicitly says 'M1.x = None', surely we can afford a 8 bytes to
> provide a special None for that reference.

Not only is there a lot of Python code written that says
    if x is None: ...
but there are dozens of pointer comparisons to Py_None in the C source
code for Python.  In this somewhat stale CVS tree, grep found 263 lines
with both "==" and "Py_None" on the same line, and 86 more with "!=" and
"Py_None" on the same line.  Py_True and Py_False appear with == and !=
an additional 45 times.  Perhaps you'd like to fix all the third-party
extension modules once you're done inspecting something like 300 sites
in the Python core.

For Py_None, at least, the pointer equality rule is enshrined in the API
documentation:
    Since None is a singleton, testing for object identity (using "=="
    in C) is sufficient.
        http://www.python.org/doc/api/noneObject.html

Jeff




More information about the Python-list mailing list