[Python-Dev] [Python-3000] Pre-pre PEP for 'super' keyword (original) (raw)
Calvin Spealman ironfroggy at gmail.com
Mon Apr 30 15:09:35 CEST 2007
- Previous message: [Python-Dev] [Python-3000] Pre-pre PEP for 'super' keyword
- Next message: [Python-Dev] [Python-3000] Pre-pre PEP for 'super' keyword
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 4/30/07, Tim Delaney <tcdelaney at optusnet.com.au> wrote:
I've been working on improved super syntax for quite a while now - my original approach was 'self.super' which used getframe() and mro crawling too. I hit on using bytecode hacking to instantiate a super object at the start of the method to gain performance, which required storing the class in coconsts, etc. It turns out that using a metaclass then makes this a lot cleaner.
> However, I seem to think that if the thisclass PEP goes through, > your version can be simplified as well. No tricky stuffy things in > cells would be needed, but we can just expand the super 'keyword' to > super(thisclass, self), which has been suggested at least > once. It seems this would be much simpler to implement, and it also > brings up a second point. > > Also, I like that the super object is created at the beginning of the > function, which my proposal couldn't even do. It is more efficient if > you have multiple super calls, and gets around a problem I completely > missed: what happens if the instance name were rebound before the > implicit lookup of the instance object at the time of the super call? You could expand it inline, but I think your second point is a strong argument against it. Also, sticking the super instance into a cell means that inner classes get access to it for free. Otherwise each inner class would also need to instantiate a super instance, and thisclass (or whatever it's called) would need to be in a cell for them to get access to it instead. BTW, one of my test cases involves multiple super calls in the same method - there is a very large performance improvement by instantiating it once.
Note that I would now advocate the creation of the super object at the beginning of function, and when I talk about expanding super to super(this_class, self) I do mean doing it at the beginning of the function, just like you are saying, so we're in agreement here.
-- Read my blog! I depend on your acceptance of my opinion! I am interesting! http://ironfroggy-code.blogspot.com/
- Previous message: [Python-Dev] [Python-3000] Pre-pre PEP for 'super' keyword
- Next message: [Python-Dev] [Python-3000] Pre-pre PEP for 'super' keyword
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]