[Python-bugs-list] [ python-Bugs-829458 ] setattr(obj, BADNAME, value) does not raises exception

SourceForge.net noreply at sourceforge.net
Sat Oct 25 09:50:41 EDT 2003


Bugs item #829458, was opened at 2003-10-24 09:53
Message generated for change (Comment added) made by theller
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=829458&group_id=5470

Category: Python Library
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Dmitry Vasiliev (hdima)
Assigned to: Nobody/Anonymous (nobody)
Summary: setattr(obj, BADNAME, value) does not raises exception

Initial Comment:
Now I just realize that setattr() does not check value
of the  name argument but simply insert the named value
in __dict__ so setattr(obj, BADNAME, value) not equal
to obj.BADNAME = value. It's true for new and old style
classes and all python versions which I have tried
(1.5, 2.1, 2.2, 2.3). Should not setattr(obj, BADNAME,
value) raise appropriate exception (AttributeError or
maybe ValueError)?

For example:

>>> class Test: pass
...
>>> o = Test()
>>> setattr(o, "test.test", 100)
>>> setattr(o, "12345", 200)
>>> dir(o)
['12345', '__doc__', '__module__', 'test.test']

----------------------------------------------------------------------

>Comment By: Thomas Heller (theller)
Date: 2003-10-25 15:50

Message:
Logged In: YES 
user_id=11105

Hm, you mean setattr() should only accept strings containing
valid Python identifiers as the second argument, and choke
on something like "123" or "a.b.c.d"?

I would strongly object to this change, in fact I'm using it
quite often.

----------------------------------------------------------------------

Comment By: Dmitry Vasiliev (hdima)
Date: 2003-10-25 13:54

Message:
Logged In: YES 
user_id=388573

Ok. I'll start working on it on the next week.

----------------------------------------------------------------------

Comment By: Martin v. Löwis (loewis)
Date: 2003-10-24 22:13

Message:
Logged In: YES 
user_id=21627

I don't see it as a big problem, but I would not object much
to a change. Would you like to work on a patch?

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=829458&group_id=5470



More information about the Python-bugs-list mailing list