Unsafe import in bzrlib/index.py

Vincent Ladeuil v.ladeuil+lp at free.fr
Thu Nov 15 06:25:57 GMT 2007


>>>>> "john" == John Arbash Meinel <john at arbash-meinel.com> writes:

    john> I just noticed this:
    john> from bzrlib.lazy_import import lazy_import
    john> lazy_import(globals(), """
    john> from bzrlib import trace
    john> from bzrlib.bisect_multi import bisect_multi_bytes
    john> from bzrlib.revision import NULL_REVISION
    john> from bzrlib.trace import mutter
    john> """)

    john> In general, it isn't safe to lazy import instances
    john> because you don't actually access any members, and thus
    john> you don't actually trigger the lazy import code.  I'm
    john> actually surprised it was working. Maybe NULL_REVISION
    john> was just never present.

    john> In general, I would recommend only using lazy_import to
    john> import modules, since you don't have these problems.

Since Aaron mentioned that (lazy_import should only import
modules) I try to update all modules I modified to do just that,
never import vars or functions *whether or not* they use
lazy_import.

It's generally quite mechanical but I introduced a bug in the
launchpad plugin for lack of tests so some care should be taken.

Do we all agree about this practice or should I refrain from
continuing ?

           Vincent




More information about the bazaar mailing list