On Friday 24 January 2014 12:01 AM, David Mertz wrote:
On Thu, Jan 23, 2014 at 10:17 AM, Chris Angelico
mailto:rosuav@gmail.com> wrote: On Fri, Jan 24, 2014 at 5:14 AM, David Mertz
mailto: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.
Also it would mean that the client code imports from this package. I would like client code to remain exactly as it is (continue to import from its original package) but the behavior is enhanced once this package is imported on startup.