Message24616
Logged In: YES
user_id=945502
The two-arg type form is intended for use with classmethods,
e.g.::
>>> class C(object):
... @classmethod
... def f(cls):
... print 'C.f'
...
>>> class D(C):
... @classmethod
... def f(cls):
... super(D, cls).f()
... print 'D.f'
...
>>> D.f()
C.f
D.f
I do make use of this occasionally, so I do think it should
be documented.
The one-arg form is intended to be used as a class attribute::
>>> class C(object):
... def f(self):
... print 'C.f'
...
>>> class D(C):
... def f(self):
... self.super.f()
... print 'D.f'
...
>>> D.super = super(D)
>>> D().f()
C.f
D.f
I don't know that we should really be advertising this
one-arg form though. It requires modifying a class outside
the definition or using some metaclass hackery to be usable.
And it's misleading because it won't work, for example,
with classmethods:
>>> class C(object):
... @classmethod
... def f(cls):
... print 'C.f'
...
>>> class D(C):
... @classmethod
... def f(cls):
... cls.super.f()
... print 'D.f'
...
>>> D.super = super(D)
>>> D().f()
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
File "<interactive input>", line 4, in f
AttributeError: 'super' object has no attribute 'f'
That's why I tried to gloss over it lightly. Personally I'd
prefer that the one-arg form was just deprecated. It
introduces a lot more problems than it solves.
But if it has to be documented, it should probably say
something like "A super object created with a single
argument produces a descriptor object. This descriptor
object makes the superclass methods available on the object
returned by its __get__ method. The superclass methods are
only available when __get__ is called with an instance (not
a class)."
|
|
Date |
User |
Action |
Args |
2007-08-23 14:30:11 | admin | link | issue1163367 messages |
2007-08-23 14:30:11 | admin | create | |
|