[Python-3000] [Python-Dev] Pre-pre PEP for 'super' keyword
Steven Bethard
steven.bethard at gmail.com
Mon Apr 30 01:17:46 CEST 2007
On 4/29/07, Calvin Spealman <ironfroggy at gmail.com> wrote:
> On 4/29/07, Jim Jewett <jimjjewett at gmail.com> wrote:
> > On 4/29/07, Tim Delaney <tcdelaney at optusnet.com.au> wrote:
> > > 4. super objects are callable, and calling them will execute the super
> > > method with the same name as the instance method currently being executed.
> > > Lookup of this method occurs when the instance method is entered.
> > >
> > > class A(object):
> > > def f(self):
> > > pass
> > >
> > > class B(A):
> > > def f(self):
> > > super() # Calls A.f(self)
>
> This might run into the same issue I had to cover, where you get an
> ambiguous situation trying to distinguish between calling super and
> calling the __call__ method of the next class in the MRO.
Note that it's at least not backwards incompatible because super
objects are not currently callable. You have to make the explicit
.__call__() invocation::
>>> class C(object):
... def __call__(self):
... return 'C'
...
>>> class D(C):
... def __call__(self):
... sup = super(D, self)
... return 'D' + sup()
...
>>> d = D()
>>> d()
Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
File "<interactive input>", line 4, in __call__
TypeError: 'super' object is not callable
>>> class D(C):
... def __call__(self):
... sup = super(D, self)
... return 'D' + sup.__call__()
...
>>> d = D()
>>> d()
'DC'
That said, you're probably right here:
> We should absolutely avoid a situation in python now where X() differs
> from X.__call__()
Steve
--
I'm not *in*-sane. Indeed, I am so far *out* of sane that you appear a
tiny blip on the distant coast of sanity.
--- Bucky Katt, Get Fuzzy
More information about the Python-3000
mailing list