[Zope3-dev] interface conventions: default=_RAISE_ERROR

Guido van Rossum guido@python.org
Tue, 14 May 2002 16:32:58 -0400


> > > [Jim]
> > > Maybe we should switch to having two versions of each get method.
> > > This would be easier to implement and to document.  Anybody got
> > > a suggestion for a naming convention?

[Guido]
> > The one that raises an exception should be called __getitem__ and
> > normally invoked with obj[key] notation.

[Gary]
> Unless I misunderstand, an example of a method for which we need a
> convention is this:
> 
> def getRequestView(wrapped_object, name, request, 
> default=ComponentLookupError):
> 
> That's using the rejected error default convention,

I don't know that it's rejected just yet.  I just realized that string
searches also implement this: s.index() raises an error, s.find()
returns -1 when not found.  I'm not sure I like that very much either
as an example.

> so what we need now is a naming convention to differentiate pairs of
> methods (and functions) with signatures something like
> 
> getRequestView(wrapped_object, name, request, default=None)
> 
> vs 
> 
> getRequestView(wrapped_object, name, request)
> 
> There are many places where we will need method/function pairs to
> follow this convention, and many of them, like this example, do not
> closely parallel the get vs __getitem__ signature.
> 
> I don't have a good answer, but I thought I would clarify the problem.

Well clarified.  One possible (if verbose) naming convention would be

  getRequestViewDefault(wrapped_object, name, request, default=None)

vs 

  getRequestView(wrapped_object, name, request)

--Guido van Rossum (home page: http://www.python.org/~guido/)