[Python-Dev] 2.2=>2.3 object.__setattr__(cls,attr,value)
Guido van Rossum
guido at python.org
Tue Nov 18 23:50:33 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?
I think this was a side effect of closing a hole that allowed using
object.__setattr__ to set attributes on built-in classes. A quick
look didn't reveal anything in NEWS, but the 2.3 NEWS file is truly
huge, so it may be there. :-( Andrew Kuchling's "What's New" doesn't
claim completeness...
I think this was fixed in a later version of 2.2 too BTW.
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-Dev
mailing list