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

Stephen J. Turnbull turnbull.stephen.fw at u.tsukuba.ac.jp
Tue Jan 31 09:32:38 EST 2017


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 about trying to standardize in the
stdlib because a single method has ambiguous semantics (before, after,
"during", asynchronously, ...) and the arguments to the decorated
method are restricted so people will inevitably get it wrong.
Alternatively, if you specify the semantics with an argument you end
up with something like Lisp's "advice" function, which is a big
hairball, or multiple decorators, to disambiguate.

Personally, I don't think the explicit invocation is such a big deal
to need a standardized decorator in the stdlib.

YMMV, just expressing a few ideas.

Steve


More information about the Python-ideas mailing list