[Python-ideas] __before__ and __after__ attributes for functions

Suresh V. suresh_vv at yahoo.com
Thu Jan 23 09:11:07 CET 2014


On Thursday 23 January 2014 01:22 PM, Chris Angelico wrote:
> On Thu, Jan 23, 2014 at 6:20 PM, Suresh V. <suresh_vv at yahoo.com> wrote:
>> Can we add these two attributes for every function/method where each is a
>> list of callables with the same arguments as the function/method itself?
>>
>> Pardon me if this has been discussed before. Pointers to past discussions
>> (if any) appreciated.
>
> I'm not exactly sure what you're looking for here. What causes a
> callable to be added to a function's __before__ list, and/or what will
> be done with it?

These are modifiable attributes, so something can be added/deleted from 
the __before__ or __after__ lists.

>
> If you mean that they'll be called before and after the function
> itself, that can be more cleanly done with a decorator.

Yes. Each item in the list will be called in order immediately 
before/after each invocation of the function. This is kinda like 
decorators, but more flexible and simpler. Scope for abuse may be higher 
too :-)

Suresh






More information about the Python-ideas mailing list