setattr too promiscuous?
new_name at mit.edu
Sat Jun 16 04:49:31 CEST 2001
Would it be sensible to amend setattr so that it only permitted
assignment to attribute names that can be used with the
<var_name>.<attr_name> construction without causing a syntax error? The
possibility of doing this took me by suprise a bit:
>>> class A: pass
>>> setattr(A, '/', 'test')
['/', '__doc__', '__module__']
>>> print A./
File "<stdin>", line 1
SyntaxError: invalid syntax
I guess such a patch would break existing code, but maybe extra argument
checking in setattr it could be turned on by the "import __future__"
If people think this is a good idea, I'll submit a patch at some point.
More information about the Python-list