[MERGE] Support for lazy registation of commands

Alexander Belchenko bialix at ukr.net
Sun Aug 24 10:08:32 BST 2008


Robert Collins пишет:
> 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__ :)
> 
> bb:resubmit

Rob, currently register_command do not use any registry at all -- commands simply stored
in python dict. When you vote resubmit -- you said: this all stuff should be reworked completely.
It's unfair.

I have my personal branch that rework commands.py completely to using LazyRegistry.
If Lukas want we (together) could prepare new complex patch for this.




More information about the bazaar mailing list