At 10:34 AM 4/13/2006 -0500, Ian Bicking <[EMAIL PROTECTED]> wrote:
>And even if that wasn't a problem, it means mpz would be eagerly loaded
>along with NumPy even if it wasn't needed. Or if you had to manually
>import this operator.add-glue, then if you forget it is likely to be
>difficult to debug, because there's no *bad* code, just code that is
>missing.
PEAK addresses this problem with a decorator:
@whenImported('mpz')
def setup_for_ mpz(mpz):
@operator.add.register(...)
def ...
The 'whenImported' function checks to see if mpz is already present in
sys.modules. If so, it calls the function immediately, passing in the
named module. If not, it puts an object in sys.modules whose
__getattribute__ tries to actually import the module and then calls back
any registered functions, so that anybody else importing mpz will get the
real module.
I've actually been using this for a few years now, as the eager-vs.-lazy
problem is independent of setuptools and package activation. It comes up
any time you want to offer support for something without creating a
dependency on it.
_______________________________________________
Python-3000 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-3000
Unsubscribe:
http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com