[Zope3-dev] interface conventions: default=_RAISE_ERROR

Gary Poster garyposter@earthlink.net
Fri, 10 May 2002 19:28:20 -0400


A number of interfaces throughout Zope follow the pattern of raising an error 
on failure unless *anything* is provided as a default value.  Sometimes this 
is listed as default=None in the interface (I'm guilty, at least) and then 
explained in the interface description.

Implementation-wise, this actually means default=_marker, of course.  The 
solution to this in the Container interface may be a common one that I 
haven't noticed before: define _RAISE_ERROR=Object() (or some such) in the 
interface module itself and then use default=_RAISE_ERROR in both the 
interface and (imported from the interface module) in the implementations.

I like this; it makes sense to me.  I want to change the interfaces in 
ComponentArchitecture to use this more honest and descriptive convention.

(Now we get to the question part.  Well, soon anyway.)

However, often times in the component architecture I want to optimize the 
passing of the default value from function to method.  I would like to use 
*one* _RAISE_ERROR marker for all of the interfaces in the package.  
Currently, before making the change I describe here, my universal marker 
object is defined in the package __init__ and imported everywhere.  If I move 
the marker creation to each interface, I no longer have the pleasant 
optimization I'm using now, because each marker will be different for each 
interface.

I don't like this.  I want to fix it. :-)

There are a number of places in which one could define a marker like this--in 
a package __init__, in the main Zope package __init__, and so on, but they 
all cause an unnecessary and ugly dependency for interfaces that try to 
import them.

Instead, my suggestion is to place
 _RAISE_ERROR=Object()
in the __init__ of the Interfaces package.  An interface that wants to use 
the default marker would simply
from Interface import Interface, _RAISE_ERROR
and implementations could import from their interfaces or from the original 
declaration in the Interface package.

I like this.  But the Interface package is a bit sacrosanct.  How do folks 
feel about this?

Gary