Re: Overloading function calls

Marc Wachowitz (
8 Jun 1994 07:39:43 GMT

Tim wrote:
> I agree that's a better design. Think it does imply that, for writing
> general numeric classes, each LHS method needs to look like:

> def __binop__(x, y):
> if y has a type I know about:
> do it & return


> # don't know how to handle y
> if hasattr(y, '__rbinop__'):
> return y.__rbinop__(x)
> else:
> raise TypeError, etc

Why not just raise a specific exception (e.g. OperatorError), and let
the calling mechanism (i.e. compiler generated code / special opcode)
handle the other case? It's simpler and maybe even faster.

> def __rbinop__(y, x):
> if x has a type I know about:
> do it & return
> raise TypeError, etc


> ps: Is _anyone_ concerned about the lack of backward compatibility? I'm
> not.

Nor am I.

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