[Python-ideas] __before__ and __after__ attributes for functions

Suresh V. suresh_vv at yahoo.com
Thu Jan 23 10:35:26 CET 2014


On Thursday 23 January 2014 02:27 PM, Nick Coghlan wrote:
>
> On 23 Jan 2014 18:32, "Suresh V."
> <suresh_vv at yahoo.com
> <mailto:suresh_vv at yahoo.com>> wrote:
>  >
>  > Nicely done :-)
>  >
>  > "foo" may come from a library or something, so rather than a
> decorator we may have to monkey patch it. Unless there is a nicer solution.
>  >
>  > Will functools be a good place for something like this?
>
> Another idea along similar lines is the object model in Elk:
> http://frasertweedale.github.io/elk/ (that's a before/after/around
> subclass method model, designed specifically as an alternative to using
> super() to call up to the parent implementation).

Thanks for the link. Has some interesting ideas.

>
> The main problem with the idea of doing this as a more general feature
> for arbitrary callables is that it has most of the same downsides as
> monkey-patching while being strictly less powerful and even more
> confusing (since it would be difficult to model clearly in tracebacks).
>

While being less powerful than monkey patching, it offers a more 
disciplined way by just adding before/after functionality. I don't see 
the problems with tracebacks, they just list the before/after function, 
which is like any other function.






More information about the Python-ideas mailing list