Re: [Python-ideas] A decorator to call super()

2017-01-31 Thread Sven R. Kunze
Hi Roberto, On 31.01.2017 08:13, Roberto Martínez wrote: class MyOverridedClass(MyBaseClass): def mymethod(self, foo, **kwargs): # Do something return super().mymethod(**kwargs) What about creating a decorator to call super() after/before the overrided method? Something lik

Re: [Python-ideas] A more readable way to nest functions

2017-01-31 Thread Sven R. Kunze
On 31.01.2017 00:54, Mikhail V wrote: Great idea :) But actually that was my idea initially, so just breaking it into two lines solves the readability issue perfectly with long expressions. Although if one is chasing some kind of optimisations... I don't know, I see very often people want to s

Re: [Python-ideas] A decorator to call super()

2017-01-31 Thread Roberto Martínez
I think both are useful. I would make this configurable with a flag: class MyOverridedClass(MyBaseClass): @extendsuper(after=True) def mymethod(self, foo): ... Or maybe a pair of decorator is a better option: @pre_super and @post_super El mar., 31 ene. 2017 a las 13:07, Sven R. K

[Python-ideas] A decorator to call super()

2017-01-31 Thread Stephen J. Turnbull
Roberto Martínez writes: > What about creating a decorator to call super() after/before the > overrided method? I think this is a reasonable idea, but you can do it yourself in a few lines, can't you? Are there any "gotchas" that make it hard to do correctly? Like Sven Kunze, I'm concerned ab

Re: [Python-ideas] A decorator to call super()

2017-01-31 Thread Thomas Kluyver
On Tue, Jan 31, 2017, at 02:32 PM, Stephen J. Turnbull wrote: > Personally, I don't think the explicit invocation is such a big deal > to need a standardized decorator in the stdlib. +1. It's one line either way, and the explicit call to super() seems clearer for people reading the code. _

Re: [Python-ideas] A decorator to call super()

2017-01-31 Thread Joao S. O. Bueno
On 31 January 2017 at 13:05, Thomas Kluyver wrote: > On Tue, Jan 31, 2017, at 02:32 PM, Stephen J. Turnbull wrote: >> Personally, I don't think the explicit invocation is such a big deal >> to need a standardized decorator in the stdlib. > > +1. It's one line either way, and the explicit call to s

Re: [Python-ideas] A decorator to call super()

2017-01-31 Thread Joao S. O. Bueno
BTW, if one can come up with a pure-Python implementation for these, I'd like to take a peek at the code, please. On 31 January 2017 at 13:57, Joao S. O. Bueno wrote: > On 31 January 2017 at 13:05, Thomas Kluyver wrote: >> On Tue, Jan 31, 2017, at 02:32 PM, Stephen J. Turnbull wrote: >>> Person

Re: [Python-ideas] A decorator to call super()

2017-01-31 Thread Yury Selivanov
On 2017-01-31 10:57 AM, Joao S. O. Bueno wrote: BUT - no, it is_not_ an easy decorator to craft - and I don't think it can be made to work cleanly without depending on implementation details of cPython. Pure Python version is certainly possible with descriptor protocol. PoC: https://gist.gith

Re: [Python-ideas] A decorator to call super()

2017-01-31 Thread Ned Batchelder
On 1/31/17 2:13 AM, Roberto Martínez wrote: > Hi, > > I find this type of code quite often: > > class MyOverridedClass(MyBaseClass): > def mymethod(self, foo, **kwargs): > # Do something > return super().mymethod(**kwargs) > > What about creating a decorator to call super() afte

Re: [Python-ideas] A decorator to call super()

2017-01-31 Thread Ryan Gonzalez
https://github.com/kirbyfan64/mirasu \-- Ryan (ライアン) Yoko Shimomura > ryo (supercell/EGOIST) > Hiroyuki Sawano >> everyone else ___ Python-ideas mailing list [email protected] https://mail.python.org/mailman/listinfo/

Re: [Python-ideas] A decorator to call super()

2017-01-31 Thread Joao S. O. Bueno
Sure - thanks - I did not even consider the descriptor mechanism, as I got focused in getting the equivalent from the __class__ cell inside the decorator code. And of course, now there is the "__init_subclass__" mechanism - a mixin version using that was as straight forward as it can be as well.