[Python-ideas] Bug? Feature? setattr(foo, '3', 4) works!

Nick Coghlan ncoghlan at gmail.com
Fri Dec 19 12:03:10 CET 2014

On 19 December 2014 at 20:57, Cem Karan <cfkaran2 at gmail.com> wrote:

> But, getting back to the main question, is this a bug or a feature?  I
> personally feel like this is a bug, and I'd like to both clarify it in the
> language spec, and have cpython modified to enforce the syntax, regardless
> of how you try to mess with an attribute.  How does everyone else feel
> about this?

Namespaces are just dictionaries. The one thing implementations may do is
to place a type restriction on the keys, so they throw TypeError if you try
to use something other than str (although *CPython* doesn't do that).

getattr/setattr/delattr would never throw SyntaxError though - that's only
thrown by the compiler.


Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20141219/5116c03f/attachment.html>

More information about the Python-ideas mailing list