On 4/19/06, Phillip J. Eby <[EMAIL PROTECTED]> wrote: [Guido] > >We could probably > >introduce this in 2.6 if the super object, when called, would return > >itself; then IMO no __future__ statement would be required since > >existing code using super would continue to work. > > I assume you mean that the compiler would expand super.attr to the magic > form, but super() would continue to be old-style.
No, I was suggesting that (perhaps) the keyword 'super', regardless of context, would expand to an object that behaves like the object returned by the current super(ClassName, self) call, but that in addition has a __call__ method that ignores its arguments and returns itself. Then super(C, self).foo(args) would be equivalent to today's super(C, self)(C, self).foo(args) and the second call would just be a no-op. I believe this is possible because the only meaningful operation on the return value of super(...) is __getattr__. But I'm not dead set on this approach. I do like the idea of supporting both the old and the new syntax for a while. > If so, then that still > *would* require __future__, since you could legitimately have a variable > named super. Unfortunately, yes. I'd been hoping that since it's been a built-in since 2.2, code that uses the name super in any other way would be rare enough not to care about breaking it. But that's not a very safe assumption. I think that if we require from __future__ import super_keyword we might as well not bother with the b/w compatibility hack described above. > > >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 a bit tricky to do with a super keyword since the compiler isn't supposed to know what the decorators mean, so it can't switch to this interpretation depending on whether @staticmethod is present (there could be a different decorator that happens to have a similar effect). -- --Guido van Rossum (home page: http://www.python.org/~guido/) _______________________________________________ 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