[merge] Registry

Aaron Bentley aaron.bentley at utoronto.ca
Thu Oct 12 00:34:16 BST 2006


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

John Arbash Meinel wrote:
> Robert Collins wrote:
>> On Thu, 2006-09-21 at 16:28 -0500, John Arbash Meinel wrote:
>>
>> John and I talked on IRC and we are mostly in agreement now... sometime
>> soon should see a new patch :)
>>
>> -Rob
> 
> Attached is an updated Registry, which defers to helper classes for
> handling whether to lazy import or not.
> 
> And it lessens how much Registry tries to look like a dictionary.

I figured Rob would review this one, since he's the one who wanted
changes.  But here goes...

Okay, I'm left wondering about the intended usage.  How would we use
this to replace the merge-type registry, for example?  Register all the
classes?

It seems like it would be very, very common to do

obj = registry.get(key)(arg1, arg2, ...)

Is it worth supporting this explicitly?

I'm a little uncomfortable with the 'info' idea.  It seems like, for a
given registry, you'd want to have the same 'info' about all registered
objects.  If you were registering Commands, you might want to register
aliases, parameters, options, and help.  Whatever you registered, you'd
want it to be consistent.  Wouldn't it be better for a each registry to
have its own Info type?

class CommandInfo(object):

    def __init__(self, params, options, aliases):
        self.params = params
        self.options = options
        self.aliases = aliases

command_registry = Registry(CommandInfo)

Otherwise, it looks good to me.

> +    def register_lazy(self, key, module_name, member_name,
> +                      help=None, info=None,
> +                      override_existing=False):
> +        """Register a new object to be loaded on request.
> +
> +        :param module_name: The python path to the module. Such as 'os.path'.
> +        :param member_name: The member of the module to return, if empty or 
> +                None get() will return the module itself.
> +        :param help: Help text for this entry. This may be a string or
> +                a callable.
> +        :param info: More information for this entry. Registry 

^^^ appears to have an incomplete thought.

Aaron
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFLX930F+nu1YWqI0RAhMfAJ9bWUcp1l9yYwzXoFAjTxl98IlR1QCfdC/t
shRYqNh32Fwia9owolnNuL4=
=perL
-----END PGP SIGNATURE-----




More information about the bazaar mailing list