On 4/19/06, Guido van Rossum <[EMAIL PROTECTED]> wrote:
That's not how it works (and that's good; refusing the temptation to guess, and what not :) super() cannot make any assumptions about the next class in the MRO, and since you don't *have* a class in a staticmethod, it has no way to find out. staticmethods just can't sensibly call 'their baseclass method' (unless they're really just "explicit classmethods", like __new__, but those best be real classmethods (even __new__ :))
Currently, super(ThisClass) returns an 'unbound super object', which is not a proxy for 'the next class' but rather an descriptor that would get the right proxy object upon retrieval:
>>> class X(object):
... @staticmethod
... def static(*args):
... print "X.static%r" % (args,)
...
>>> class Y(X):
... @staticmethod
... def static(*args):
... print " Y.static%r" % (args,)
... super(Y).static(*args)
...
>>> Y.static()
Y.static()
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "<stdin>", line 5, in static
AttributeError: 'super' object has no attribute 'static'
>>> y = Y()
>>> y.static()
Y.static()
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "<stdin>", line 5, in static
AttributeError: 'super' object has no attribute 'static'
And to prove it's a descriptor:
>>> class Z(X):
... @staticmethod
... def static(*args):
... print "Z.static%r" % (args,)
... super(Z).__get__(Z, None).static(*args)
...
>>> Z.static()
Z.static()
X.static()
>>> Z().static()
Z.static()
X.static()
Doing super(Z).__get__(Z, None).static is just as static as calling X.static, though (with the only difference being that you name Z multiple times, instead of naming X multiple times.) It doesn't take MI into account at all.
And yes, staticmethods are damned near useless. Let's not worry about them calling their baseclass methods -- they honestly shouldn't.
> >Oh, I believe super() also supports static and/or class methods. I'm
> >not sure how to handle this but I'm sure you can think of something.
>
> If super.foobar(args) -> super(ThisClass,firstarg).foobar(args), then it
> will Just Work(TM) for class methods, since their first argument is the
> class, and super(someclass,myclass).aClassMethod(...) is the normal way of
> invoking a superclass classmethod.
But how about static methods? Inside a static method, I believe you're
allowed to write
super(ThisClass).foobar(args)
which would call
ThisClass.__base__.foobar(args)
(assuming single inheritance for a moment) i.e. nothing is added to
the argument list.
That's not how it works (and that's good; refusing the temptation to guess, and what not :) super() cannot make any assumptions about the next class in the MRO, and since you don't *have* a class in a staticmethod, it has no way to find out. staticmethods just can't sensibly call 'their baseclass method' (unless they're really just "explicit classmethods", like __new__, but those best be real classmethods (even __new__ :))
Currently, super(ThisClass) returns an 'unbound super object', which is not a proxy for 'the next class' but rather an descriptor that would get the right proxy object upon retrieval:
>>> class X(object):
... @staticmethod
... def static(*args):
... print "X.static%r" % (args,)
...
>>> class Y(X):
... @staticmethod
... def static(*args):
... print " Y.static%r" % (args,)
... super(Y).static(*args)
...
>>> Y.static()
Y.static()
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "<stdin>", line 5, in static
AttributeError: 'super' object has no attribute 'static'
>>> y = Y()
>>> y.static()
Y.static()
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "<stdin>", line 5, in static
AttributeError: 'super' object has no attribute 'static'
And to prove it's a descriptor:
>>> class Z(X):
... @staticmethod
... def static(*args):
... print "Z.static%r" % (args,)
... super(Z).__get__(Z, None).static(*args)
...
>>> Z.static()
Z.static()
X.static()
>>> Z().static()
Z.static()
X.static()
Doing super(Z).__get__(Z, None).static is just as static as calling X.static, though (with the only difference being that you name Z multiple times, instead of naming X multiple times.) It doesn't take MI into account at all.
And yes, staticmethods are damned near useless. Let's not worry about them calling their baseclass methods -- they honestly shouldn't.
--
Thomas Wouters <[EMAIL PROTECTED]>
Hi! I'm a .signature virus! copy me into your .signature file to help me spread!
_______________________________________________ Python-3000 mailing list Python-3000@python.org http://mail.python.org/mailman/listinfo/python-3000 Unsubscribe: http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com