Re: Overloading function calls

Marc Wachowitz (
8 Jun 1994 21:53:31 GMT

Guido wrote:
[raise exception to make the runtime system call __rbinop__]
> The problem with using exceptions for such purposes is that if the
> exception is raised unexpectedly somewhere inside the implementation
> of __binop__ (which has no a priory reason to expect this nor to catch
> it), the caller would mistakenly think that __binop__ wanted the RHS
> dispatch version to be tried, while actually it was in deep trouble.

If the particular exception is only used for that purpose, such an error
would be quite unlikely, since only operator methods would raise it - we
might even play the exception in some special module and give it a clear
name, such that nobody would unintentionally use it in other situations;
e.g. "operator.TryReverseOperator". Another way to simplify the protocol
would be to let a special value (e.g. an object specifically created for
that purpose, thus obviously being unique, and certainly not used in any
other context) signal the intention, thus avoiding even all the problems
of exceptions. I doubt anyone is calling operator methods directly, thus
Python code wouldn't usually have to deal with it.

* wonder everyday * nothing in particular * all is special *
Marc Wachowitz <>