[Zope3-dev] RFC: Change in automatic detection of provided interfaces

Jim Fulton jim at zope.com
Wed Apr 6 08:47:58 EDT 2005


A recent simplification was made to adapter and utility registration.
When registering adapters, the provided interface can be ommitted
if the registered factory implements a single interface.  Similarly,
when registering utilities, the provided interface can be ommitted
if the registered component provides a single interface.

The intent is that if you have something like:

   class MyClass:
       implements(IFoo)

       ...

you do not have to repeat IFoo in the registration.

The current scheme runs into problems if you use inheritence:

   class MyClass(SomeBase):
       implements(IFoo)

Then declarations in the base class cause the subclass
to implement multiple interfaces.

I'd like to make the following change to algorithm for determing
the provided interface if nothing is specified in the rgistration:

   For adapters, if the registered factory directly implements
   a single interface, then that interface will be used.  Inherited
   interfaces will not be considered.  If the factory directly implements
   no interfaces or more than one interface, then a provided interface
   must be provided in the registration.

   For utilities, if the registered component directly provides no
   interfaces and its class directly implements
   a single interface, then that interface will be used.  Inherited
   interfaces will not be considered.  If the component directly
   provides any interfaces or if its class directly implements
   no interfaces or more than one interface, then a provided interface
   must be provided in the registration.

So, for example, if we have:

   class B:
      implements(IB)

   class S(B)
      implements(IS)

we can register S or an instance of S without specifying a provided
interface.  The interface IS will be used.

However, with:

   class S2(B):
      pass

You would have to sp[ecify a provided interface if you registered S2
or an instance of S2.

Thoughts?

Jim

-- 
Jim Fulton           mailto:jim at zope.com       Python Powered!
CTO                  (540) 361-1714            http://www.python.org
Zope Corporation     http://www.zope.com       http://www.zope.org


More information about the Zope3-dev mailing list