A interesting difference between classic and new style objects
aleax at aleax.it
Mon Jan 7 04:30:13 EST 2002
"Oren Tirosh" <oren-py-l at hishome.net> wrote in message
news:mailman.1010392449.17847.python-list at python.org...
> With a new style objects built-in functions such as repr, iter etc. see
> original method with which the object was born even after it is overridden
> by assignment.
> Is this a bug or a feature?
It would, on the face of it, appear to contradict PEP 252:
sub "Specification of the class-based introspection API"
sub "5. Precedence rules":
In other words, for data attributes (those with a __set__
method), the static definition overrides the dynamic definition,
but for other attributes, dynamic overrides static.
However, PEP 252 also specifies:
The introspection API is a read-only API. We don't define the
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
considered off-limits. A future PEP may define some semantics for
some such assignments.
As here we are indeed dealing with "assignment to [an item] of
a __dict__", we may be in the grey zone to "be considered
off-limits". Some clarification would surely be welcome.
More information about the Python-list