Comment 2 for bug 98401

Revision history for this message
Gary Poster (gary) wrote :

> However, if you then access any of the deferred imports in
> zope/component/__init__.py that come from zope/component/_api.py, the
> adapter hook registration in _api.py is called so that zope.component is
> now set up correctly with zope.interface, and the adaptation will work.

I agree that this does not indicate that something needs to change in the deferredimport code, unless the basic approach changes in some way I can't see.

The fact that you can have such different behavior (interface adaptation working or not working) depending on whether you access an attribute in the zope.component module is the bug (or the unpleasant and surprising fragility?). The interaction of deferredimport and the hook registration in _api.py causes the problem.

Here are a few solutions.

- move getSiteManager and the adapter hook and the adapter hook registration back in __init__.py

- move just the adapter hook and its registration to another module that is imported directly within __init__.py and that itself imports zope.component, so it is automagically regsitered on import as currently intended, and when it accesses zope.component.getSiteManager in the hook the deferredimport works as expected.

- remove the automagical adapter hook registration and require explicit registration for clients of zope.component who want to use the interface syntax.

I actually don't mind the automagic in this case, but can see arguments either way. Option 2 seems kludgy but it's the best I see there. The other tricky variants to the approach that I can imagine possibly working don't seem any better.