[Python-bugs-list] [ python-Bugs-829458 ] setattr(obj, BADNAME,
value) does not raises exception
SourceForge.net
noreply at sourceforge.net
Mon Oct 27 20:00:16 EST 2003
Bugs item #829458, was opened at 2003-10-24 10:53
Message generated for change (Comment added) made by tzot
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: Christos Georgiou (tzot)
Date: 2003-10-28 03:00
Message:
Logged In: YES
user_id=539787
Note: there is a valid_identifier function in
Objects/typeobject.c which is being used by the __slots__
mechanism and I believe is quite handy; however, it is
declared as static.
----------------------------------------------------------------------
Comment By: Dmitry Vasiliev (hdima)
Date: 2003-10-26 11:09
Message:
Logged In: YES
user_id=388573
Give me some use case examples. Maybe you use object's
__dict__ like general purpose dictionary? If so, it seems
ugly for me.
----------------------------------------------------------------------
Comment By: Thomas Heller (theller)
Date: 2003-10-25 16: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 14: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 23: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