deferredimport breaks some standalone usages of zope.component
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Zope 3 |
Fix Released
|
Medium
|
Gary Poster |
Bug Description
when zope.component is used by itself (i.e., without any other Zope code than its own dependencies having been imported), then the following fails.
>>> import zope.component
>>> import zope.interface
>>> class IFoo(interface.
... pass
...
>>> class Bar(object):
... pass
...
>>> class BarToFooAdapter
... zope.interface.
... zope.component.
... def __init__(self, obj):
... self.bar = obj
...
>>> zope.component.
>>> bar = Bar() # implements IBar
>>> IFoo(bar)
Traceback (most recent call last):
...
TypeError: ('Could not adapt', <Bar instance at ...>, <InterfaceClass IFoo>)
However, if you then access any of the deferred imports in zope/component/
For instance:
>>> ignore = zope.component.
>>> IFoo(bar)
<BarToFooAdapter instance at ...>
A solution to this that keeps the deferred import mechanism in place is not obvious to me, but hopefully it will be to someone else.
Gary, did you register an adapter hook, so that calling an interface will work? I do not think this is a deferred import bug.