[Python-ideas] __before__ and __after__ attributes for functions
Chris Angelico
rosuav at gmail.com
Thu Jan 23 19:17:28 CET 2014
On Fri, Jan 24, 2014 at 5:14 AM, David Mertz <mertz at gnosis.cx> wrote:
> from library import foo
> @prepostcall
> def foo(*args, **kws):
> return foo(*args, **kws)
That's going to infinite-loop, so you'd need to do an 'as' import:
from library import foo as foo_original
@prepostcall
def foo(*args, **kws):
return foo_original(*args, **kws)
Of course, this assumes you want to do a 'from' import in the first
place, rather than the more common approach of referencing
'library.foo()' - if the latter, then it is monkeypatching you need.
ChrisA
More information about the Python-ideas
mailing list