[Python-ideas] A decorator to call super()
Ned Batchelder
ned at nedbatchelder.com
Tue Jan 31 14:33:57 EST 2017
More information about the Python-ideas mailing list
Tue Jan 31 14:33:57 EST 2017
- Previous message (by thread): [Python-ideas] A decorator to call super()
- Next message (by thread): [Python-ideas] A decorator to call super()
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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() after/before the > overrided method? Something like that: > > class MyOverridedClass(MyBaseClass): > @extendsuper > def mymethod(self, foo): > # Do something > > Sorry if this has already been proposed, I have not found anything > similar in the list. With all of the possible details that need to be covered (before/after, what args to pass along, what to do with the return value), this doesn't seem like a good idea to me. The most common use of super is in __init__, where the value should not be returned, and the example given here returns the value, so right off the bat, the example is at odds with common usage. The super call is just one line, and the decorator would be one line, so there's no savings, no improvement to expressivitiy, and a loss of clarity: -1. --Ned.
- Previous message (by thread): [Python-ideas] A decorator to call super()
- Next message (by thread): [Python-ideas] A decorator to call super()
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-ideas mailing list