An interesting difference between classic and new style objects

Alex Martelli aleax at aleax.it
Mon Jan 7 08:42:22 EST 2002


"Oren Tirosh" <oren-py-l at hishome.net> writes:
    ...
> >     effect of assignment to any of the special attributes (__dict__,
> >     __class__ and __bases__), nor the effect of assignment to the
> >     items of a __dict__.  Generally, such assignments should be
    ...
> In this case __repr__ is not a special attribute.  It is a user attribute
> with a well-known name that some builtin functions refer to.  There are
even

Yes, but what is assigned is one of "the items of a __dict__" (that
of the instance).  At least, that's the only reason I can see why
this could behave strangely.


> examples of this happening for attributes without underscores.

Yes, nothing is specified regarding the key of "the item of a __dict__"
either having or lacking underscores.


> There is no use of the introspection API, either.

There is intrinsic use of mechanisms specified in PEP 252.

> I believe that assignment
> of attributes is well within the bounds of the basic language definition
and
> yet it produces different results for classic and new style objects.

Yes to both beliefs.  But then, several "Differences between classic
classes and new-style classes" are recapped as "can't be considered to
be real bugs" in http://www.python.org/2.2/bugs.html (this specific
one you've observed isn't listed, but then the last entry in the list
is "I'm sure there are more differences that are relevant to the conversion
of classic classes to new-style classes, but I can't think of then right
now".

The advice on said page is to report "a bug not listed above" through
http://sourceforge.net/bugs/?group_id=5470 -- and given the collocation
of the advice this would seem to apply to this latter category of "can't
be considered to be real bugs" as well as to real ones.


Alex






More information about the Python-list mailing list