[Python-Dev] Assignment to None

Curt Hagenlocher curt at hagenlocher.org
Mon Jun 9 04:24:55 CEST 2008

My apologies if this is one of those "dead horse" issues.  The
following seems a little inconsistent to me:

>>> c = C()
>>> c.None
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: C instance has no attribute 'None'
>>> c.None = 'foo'
  File "<stdin>", line 1
SyntaxError: assignment to None
>>> setattr(c, 'None', 'foo')
>>> c.None

So, it's okay to setattr the attribute name "None" but not okay to set
it directly?  Is this deliberate or is it an unintentional side effect
of parser changes to prevent assignment to None?

Curt Hagenlocher
curt at hagenlocher.org

More information about the Python-Dev mailing list