[Interface-dev] zope.interface calling an interface with no arguments

Daniel Krech eikeon at eikeon.com
Wed Aug 31 19:49:58 EDT 2005


Hi All,

Looking at the Interface-dev Info Page this appears to be the right  
email list to send this along too:

[[[

We're in the process of adding Interfaces to rdflib using Zope  
Interfaces and also replacing rdflib's home brewed plugin system. So  
far things are going well, but we've run across something we'd like  
to be able to do, namely, create an instance by calling the interface  
with no arguments. For example:

from zope.interface import Interface, implements


class Graph(Interface):
     """ A Graph..."""


class DefaultGraph(object):
     implements(Graph)

verifyClass(Graph, DefaultGraph)


from zope.interface.adapter import AdapterRegistry, Default
from zope.interface import providedBy

registry = AdapterRegistry()

def hook(provided, object):
     adapter = registry.lookup1(providedBy(object), provided, '')
     if object==Default:
         return adapter()
     else:
         return adapter(object)

from zope.interface.interface import adapter_hooks
adapter_hooks.append(hook)

registry.register([Default], Graph, '', DefaultGraph)


g = Graph(Default) # currently

g = Graph() # This is what we'd like to be able to do to get an  
instance of DefaultGraph (since it's registered as the Default for  
Graph).

So far people seem to like the idea. So we're sending the idea along  
to the Zope developers.

]]] -- http://rdflib.net/blog/2005/08/31/zope.interface_support/


Cheers,
Daniel Krech, http://eikeon.com/  --  http://rdflib.net/






More information about the Interface-dev mailing list