Provides(*interfaces)
Cache instance declarations
Instance declarations are shared among instances that have the same declaration. The declarations are cached in a weak value dictionary.
the size of the weakvalue dictionary. For the assertions to be meaningful, we need to force garbage collection to make sure garbage objects are, indeed, removed from the system. Depending on how Python is run, we may need to make multiple calls to be sure. We provide a collect function to help with this:
>>> import gc >>> def collect(): ... for i in range(4): ... gc.collect()
)
>>> collect() >>> before = len(InstanceDeclarations)
>>> class C(object): ... pass
>>> from zope.interface import Interface >>> class I(Interface): ... pass
>>> c1 = C() >>> c2 = C()
>>> len(InstanceDeclarations) == before 1
>>> directlyProvides(c1, I) >>> len(InstanceDeclarations) == before + 1 1
>>> directlyProvides(c2, I) >>> len(InstanceDeclarations) == before + 1 1
>>> del c1 >>> collect() >>> len(InstanceDeclarations) == before + 1 1
>>> del c2 >>> collect() >>> len(InstanceDeclarations) == before 1
__safe_for_unpickling__
(type:
bool
)
True