<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, Jan 23, 2014 at 10:17 AM, Chris Angelico <span dir="ltr"><<a href="mailto:rosuav@gmail.com" target="_blank">rosuav@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">On Fri, Jan 24, 2014 at 5:14 AM, David Mertz <<a href="mailto:mertz@gnosis.cx">mertz@gnosis.cx</a>> wrote:<br>
> from library import foo<br>
> @prepostcall<br>
> def foo(*args, **kws):<br>
> return foo(*args, **kws)<br>
<br>
</div>That's going to infinite-loop, so you'd need to do an 'as' import:<br>
<br>
from library import foo as foo_original<br>
@prepostcall<br>
def foo(*args, **kws):<br>
return foo_original(*args, **kws)<br>
<br>
Of course, this assumes you want to do a 'from' import in the first<br>
place, rather than the more common approach of referencing<br>
'library.foo()' - if the latter, then it is monkeypatching you need.<br></blockquote><div><br></div><div>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.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="HOEnZb"><div class="h5"><br>
ChrisA<br>
_______________________________________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" target="_blank">https://mail.python.org/mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" target="_blank">http://python.org/psf/codeofconduct/</a><br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br>Keeping medicines from the bloodstreams of the sick; food <br>from the bellies of the hungry; books from the hands of the <br>uneducated; technology from the underdeveloped; and putting <br>
advocates of freedom in prisons. Intellectual property is<br>to the 21st century what the slave trade was to the 16th.<br>
</div></div>