setattr too promiscuous?
Alex
new_name at mit.edu
Fri Jun 15 22:49:31 EDT 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')
>>> dir(A)
['/', '__doc__', '__module__']
>>> print A./
File "<stdin>", line 1
print A./
^
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__"
command.
If people think this is a good idea, I'll submit a patch at some point.
Alex.
More information about the Python-list
mailing list