[Python-Dev] 2.2=>2.3 object.__setattr__(cls,attr,value)
David Eppstein
eppstein at ics.uci.edu
Tue Nov 18 22:23:59 EST 2003
In 2.2 I was able to call object.__setattr__(cls,attr,value)
where cls is a new-style type (first argument of a classmethod),
and attr and value are the name and value of a class attribute I want to
create programmatically. I just upgraded to 2.3 but now when I try it I
get
>>> class foo(object):pass
...
>>> object.__setattr__(foo,'foo',None)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: can't apply this __setattr__ to type object
Instead I apparently have to call
>>> type(foo).__setattr__(foo,'foo',None)
Anyway, my question: no harm done here because this was in undeployed
code and I've found a workaround, but shouldn't this have at least been
mentioned in "What's New in Python 2.3"? Or maybe this is one of the
some-other-change-with-far-reaching-consequences things that was
mentioned and I just don't see the connection?
--
David Eppstein http://www.ics.uci.edu/~eppstein/
Univ. of California, Irvine, School of Information & Computer Science
More information about the Python-Dev
mailing list