[Zope3-dev] interface conventions: default=_RAISE_ERROR

Guido van Rossum guido@python.org
Sun, 12 May 2002 19:54:59 -0400


> On Sunday 12 May 2002 07:05 pm, Tres Seaver wrote:
> > I think a "pure" marker, one which cannot possibly
> > be confused with any *real* value passied by a client, is the essence
> > here

I understand that's what the pattern is trying to capture, but I have
a problem with an argument that has a default value that cannot be
specified implicitly.  I know that this occurs in core Python (the 3rd
arg to getattr is the only example I know of) but in retrospect I
think that was a mistake, and I prefer using some other "impossible"
value as the default, and documenting what it is.

An example of what I think is a better approach: file.read(-1) is
documented as equivalent to file.read(), both meaning "read until
EOF".  This is intentional, so that a wrapper class can define a read
method with a default argument value of -1 and simply pass this to the
underlying read method.  Using the "default marker pattern", a wrapper
would always have to define its own marker and write

    if count is _marker:
       s = self.__file.read()
    else:
       s = self.__file.read(count)

I strongly recommend to make the default value a documented and
obtainable value rather than something hidden.  If None can be used,
that is of course preferred; but I presume there's a reason why None
must be treated as an "ordinary" value in the interfaces discussed
here, and that's why I suggested using an exception -- it's unlikely
that an exception class is otherwise a useful value.

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