[MERGE] Support for lazy registation of commands
Lukáš Lalinský
lalinsky at gmail.com
Sun Aug 24 10:10:56 BST 2008
Dňa Ne, 2008-08-24 o 19:02 +1000, Robert Collins napísal:
> On Sun, 2008-08-24 at 11:50 +0300, Alexander Belchenko wrote:
> > +class LazyCommandProxy(object):
> > +
> > + def __init__(self, module, name, aliases):
> > + self._module = module
> > + self._name = name
> > + self.aliases = aliases
> > + self.__name__ = name
> > +
> > + def __call__(self, *args, **kwargs):
> > + cmd_module = __import__(self._module, globals(), locals(), [True])
> > + cmd_class = getattr(cmd_module, self._name)
> > + return cmd_class(*args, **kwargs)
> >
> >
> > Why for you pass [True] as last argument to __import__? IMO, you don't need
> > to pass there anything. According to Python documentation 4th argument
> > lists the names that should be imported from module. So importing name
> > 'True' is useless IIUC.
> >
> > bb:tweak
>
> Also, we have lazy registries already, we shouldn't be writing any code
> that calls __import__ :)
Sorry, I have no interest in rewriting all the command handling code. I
wrote this for qbzr, which means it had to work with the current
bzrlib.command code. I just thought it would be useful for other
plugins, so I submitted a patch using the same approach as qbzr.
Lukas
More information about the bazaar
mailing list