[Zope-dev] make zope.component.registry.Components inherit from dict?

Martin Aspeli optilude+lists at gmail.com
Tue Nov 24 02:07:06 EST 2009

Chris McDonough wrote:

> OK after rereading this, I think we may be massively overthinking this.  The 
> above is getting kinda silly.  I can't think of a use case where being able to 
> alternate between:
>    reg.utils['root_factory']
> and
>    reg.getUtility(IAnonymousUtility, name='root_factory')
> ... is at all useful.  I may be wrong.  Can you think of one?
> If not, it's a lot easier to document:
> "The utils attribute of a registry is a dictionary that may contain arbitrary 
> key/value pairs."
> Than it is to document:
> "The utils attribute of a registry is a DictInterface which exposes the Python 
> dictionary API which does unnamed utility registrations using the 
> IAnonymousUtility interface as the utility interface and the key value passed 
> to the various API methods as the utility name...... <and so on>"
> Could maybe we instead just do:
>   class Components(object):
>        def __init__(self, name='', bases=()):
>            self.utils = {}
> This would be faster, simpler to document, and would require exactly one line 
> of code.

Except at this point we've lost all the other ZCA stuff. You can't 
override with a local utility, for example. In fact, this is not a ZCA 
"utility" at all, it's just a key-value pair in a threadlocal. It 
doesn't have any consistency with named utilities or adapters or any 
other aspect of the ZCA.

I'm not saying having "just" a thread-local dictionary is a bad idea, 
but maybe it's not a ZCA responsibility at all. Why would you really 
expect it on getSiteManager().utils or whatever? Maybe it's better to 
look into the stacked variables that Pylons uses for some of its 
configuration stuff?


Author of `Professional Plone Development`, a book for developers who
want to work with Plone. See http://martinaspeli.net/plone-book

More information about the Zope-Dev mailing list