On 4/29/07, Calvin Spealman <[EMAIL PROTECTED]> wrote:
> On 4/29/07, Jim Jewett <[EMAIL PROTECTED]> wrote:
> > On 4/29/07, Tim Delaney <[EMAIL PROTECTED]> 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
_______________________________________________
Python-3000 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-3000
Unsubscribe:
http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com