PEP 335: Overloadable Boolean Operators - Official Posting

Greg Ewing greg at
Mon Sep 13 07:07:52 CEST 2004

John Roth wrote:
> A second comment is that I think you need seven slots - the
> 'rand2' and 'ror2' slots seem to be missing.

If you're talking about the C-level slots, that's not
a mistake. If you look, you'll find that *none* of the
__rxxx__ methods exist at the C level. If the left
operand doesn't define a slot for an operator, the
*same* C-level slot of the right operand is called,
with the operands in the same order. The implementations
of these slots for user-defined classes sort this out
and call __xxx__ or __rxxx__ Python methods as

> A third comment is that I think the 'and1' and 'or1'
> should return either True or False, meaning 'short
> circuit with the current value on top of the stack',
> or 'continue with the evaluation with the current
> value on top of the stack'. I'd like to see a discussion
> of why this (IMO conceptually simpler) option
> wasn't chosen.

It's in the interests of generality. Without use cases,
it's admittedly unknown whether this amount of generality
will ever be needed.

Greg Ewing, Computer Science Dept,
University of Canterbury,	
Christchurch, New Zealand

More information about the Python-list mailing list