Patches item #1727209, was opened at 2007-05-28 22:30 Message generated for change (Comment added) made by gvanrossum You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1727209&group_id=5470
Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: Core (C code) Group: Python 3000 Status: Open Resolution: None Priority: 5 Private: No Submitted By: Guido van Rossum (gvanrossum) Assigned to: Guido van Rossum (gvanrossum) Summary: First steps towards new super (PEP 367) Initial Comment: A half-assed start of an implementation for super. This is lacking parser support; instead, for now, you have to have a keyword-only argument named super, e.g. def foo(self, arg, *, super): return super.foo(arg) + 1 Note that the first version changes method lookup for bound method lookup but not yet for unbound method lookup. E.g. if f is defined in class B, and class C derives from B, C().f returns a bound method object whose im_class attribute is set to B (as opposed to C as it used to be) but C.f returns an unbound method object with im_class set to C. (I hope to this in a later version.) ---------------------------------------------------------------------- >Comment By: Guido van Rossum (gvanrossum) Date: 2007-06-06 17:00 Message: Logged In: YES user_id=6380 Originator: YES Sorry, forgot to add test_super.py to the patch. File Added: super2.diff ---------------------------------------------------------------------- Comment By: Guido van Rossum (gvanrossum) Date: 2007-06-06 16:57 Message: Logged In: YES user_id=6380 Originator: YES OK, here's today's final version (I hope). This fixes test_scope.py (wasn't too hard after all) and updates the docstring for super(). Question to all: is writing super() acceptable? File Added: super2.diff ---------------------------------------------------------------------- Comment By: Guido van Rossum (gvanrossum) Date: 2007-06-06 16:01 Message: Logged In: YES user_id=6380 Originator: YES Here's a better version that lets you use super() as a shorthand for super(__class__, <firstarg>). test_scope.py still fails though. File Added: super2.diff ---------------------------------------------------------------------- Comment By: Guido van Rossum (gvanrossum) Date: 2007-06-06 14:53 Message: Logged In: YES user_id=6380 Originator: YES I'm starting a new series of patches, super2.diff. These use a completely different tack, inserting a cell variable __class__ into the class shared by all the methods and initialized to the class after it's constructed. Right now, this allows us to write super(__class__, self).method() -- I want to evolve it so that eventually you can write super.method() and super will do the lookup of __class__ and the first argument itself. There's one failing test, testFreeVarInMethod in test_scope.py. This seems significant but I want to upload a checkpoint first. File Added: super2.diff ---------------------------------------------------------------------- Comment By: Guido van Rossum (gvanrossum) Date: 2007-05-31 19:00 Message: Logged In: YES user_id=6380 Originator: YES This breaks all class methods (as Phillip Eby pointed out): class C: @classmethod def cm(cls): return cls.__name__ class D(C): pass print(D.cm(), D().cm()) This should print "D D" but with the patch it prints "C C". ---------------------------------------------------------------------- Comment By: Guido van Rossum (gvanrossum) Date: 2007-05-31 07:45 Message: Logged In: YES user_id=6380 Originator: YES Oops, a last-minute change didn't work out. This version is better. File Added: super.diff ---------------------------------------------------------------------- Comment By: Guido van Rossum (gvanrossum) Date: 2007-05-31 07:24 Message: Logged In: YES user_id=6380 Originator: YES Here's a version that modifies the grammar so 'super' is a keyword. The compiler automatically inserts a 'super' keyword-only argument into a function's signature when the 'super' keyword is used in its body. It works! This requires the p3yk branch at -r55692 or newer. File Added: super.diff ---------------------------------------------------------------------- Comment By: Guido van Rossum (gvanrossum) Date: 2007-05-29 02:08 Message: Logged In: YES user_id=6380 Originator: YES Here's a new version. Forget about sup.py, the demos are now in Lib/test/test_super.py. Only a few tests fail due to the semantic change (about six files have 1-2 failures each). I think this is acceptable. File Added: super.diff ---------------------------------------------------------------------- Comment By: Guido van Rossum (gvanrossum) Date: 2007-05-28 23:23 Message: Logged In: YES user_id=6380 Originator: YES And a new sup.py example demonstrating that the new patch works. File Added: sup.py ---------------------------------------------------------------------- Comment By: Guido van Rossum (gvanrossum) Date: 2007-05-28 23:22 Message: Logged In: YES user_id=6380 Originator: YES Here's a new version of the patch where C.f.im_class (in the above example) correctly returns B. File Added: super.diff ---------------------------------------------------------------------- Comment By: Guido van Rossum (gvanrossum) Date: 2007-05-28 22:31 Message: Logged In: YES user_id=6380 Originator: YES Here is sup.py, a small demo of how this is supposed to work. File Added: sup.py ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1727209&group_id=5470 _______________________________________________ Patches mailing list Patches@python.org http://mail.python.org/mailman/listinfo/patches