"Tony Nelson" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
| At 4:46 PM +0100 6/9/08, Michael Foord wrote:
| Or perhaps CPython should just stop trying to detect this at compile 
time.
| Note that while assignment to ".None" is not allowed, setattr(foo, 
"None",
| 1) then referencing ".None" is allowed.
|
| >>> f.None = 1
| SyntaxError: assignment to None
| >>> f.None
| Traceback (most recent call last):
|  File "<stdin>", line 1, in ?
| AttributeError: 'Foo' object has no attribute 'None'
| >>> setattr(f, 'None', 1)
| > f.None
| 1

I was a little surprised by this.  ISTM that f.None should consistently 
work or not work both for getting and setting.  The last result could be 
considered a bug rusulting from getting disabling depending on None not 
being set, but having a backdoor that does allow it to be set.

I recently read someone (Guido?) saying that a language should start 
'strict' because it is much easier to allow something new than disallow 
something old.  Allowing 'None' and possibly other keywords as attributes 
will not break code (that does not depend on the exceptions).   But I 
presume there was some thought that the restriction might prevent buggy 
code.

At the global level, the subversion does not work:
>>> globals()['None'] = 'ha'
>>> None
>>> dir()
['None', '__builtins__', '__doc__', '__name__', '__package__']
>>> globals()['None']
'ha'

tjr



_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to