[Zope3-dev] Re: "most specific" interface?
Jean-Marc Orliaguet
jmo at ita.chalmers.se
Fri Sep 16 10:07:09 EDT 2005
Philipp von Weitershausen wrote:
>Florent Guillaume wrote:
>
>
>>Philipp von Weitershausen wrote:
>>
>>
>>
>>> >>> from zope.app.content.interfaces import IContentType
>>> >>> from zope.app.file.interfaces import IFile
>>> >>> from zope.interface import directlyProvides
>>> >>> directlyProvides(IFile, IContentType)
>>>
>>>
>>Watch out! directlyProvides is evil, it *replaces* the interfaces
>>provided by something. Here, if IFile implemented something else, it
>>would be lost.
>>
>>You should always use:
>>
>> directlyProvides(ob, ISomething, directlyProvidedBy(ob))
>>
>>(Or use a convenience method to do that, I'm not sure if alsoProvides()
>>was ever implemented.)
>>
>>
>
>Yes, alsoProvides() is available in Zope 3.1. So,
>
> >>> alsoProvides(ob, ISomething)
>
>is the shorter spelling of Florent's line above.
>
>Philipp
>
>
>
>
does alsoProvides() check for interfaces already listed?
apparently not:
interface/declarations.py:
def alsoProvides(object, *interfaces):
...
directlyProvides(object, directlyProvidedBy(object), *interfaces)
what happens if you write:
>>> alsoProvides(ob, ISomething)
>>> alsoProvides(ob, ISomething)
will ISomething be provided twice? this could be a memory leak in that case.
/JM
More information about the Zope3-dev
mailing list