help on autosuper
glc at well.com
Sun Feb 2 17:38:39 CET 2003
On 26 Jan 2003 10:33:44 -0800, mis6 at pitt.edu (Michele Simionato) wrote:
>It seems "super" doesn't work the same for all special attributes:
>it works o.k. for "__doc__" but not for "__name__".
>Still I don't know why, i.e. if this is the desired effect or not.
This is mainly by design; it happens because super returns only attributes for
which PyDescr_IsData returns false. PyDescr_IsData tests if the tp_descr_set
slot is non-NULL for a particular type. In this case, both attr and __doc__ are
stored as simple strings in C's dict; strings do not have a tp_descr_set method,
so PyDescr_IsData returns false and the super returns the attribute. __name__
refers to a getset_descriptor instance, and getset_descriptors do have a
tp_descr_set method, so the __name__ attribute is ignored and you get the error.
Here's GvR's reason for introducing the PyDescr_IsData check (from a response to
an old bug report http://www.python.org/sf/505028 ):
- super(C, C()).__class__ would return the __class__
attribute of C()
rather than the __class__ attribute of the super object.
confusing. To fix this, I decided to change the semantics
so that it only applies to code attributes, not to data
After all, overriding data attributes is not supported
So the behavior is basically by design, though it is a bit of a quirk that super
will retrieve non-descriptor data attributes.
More information about the Python-list