On Thu, Jan 23, 2014 at 10:17 AM, Chris Angelico <rosuav@gmail.com> wrote:
On Fri, Jan 24, 2014 at 5:14 AM, David Mertz <mertz@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.

All true.  For some reason I was thinking of the timing of the binding wrongly re. the infinite-loop. But yes, obviously using a different name in an 'as' import solves that.
 

ChrisA
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/



--
Keeping medicines from the bloodstreams of the sick; food
from the bellies of the hungry; books from the hands of the
uneducated; technology from the underdeveloped; and putting
advocates of freedom in prisons.  Intellectual property is
to the 21st century what the slave trade was to the 16th.