code review

Ian Kelly ian.g.kelly at
Sat Jul 14 11:26:53 CEST 2012

On Fri, Jul 13, 2012 at 5:09 PM, Terry Reedy <tjreedy at> wrote:
>> From now on, for each operator I would have to remember wether it
>> is a supposedly comparison operator or not.
> I believe the following rule is true: if a op b is True or False raises,

I don't follow.  Raises what?

> then op is a potentially chained comparison operation. They are (not) equal
> (and (not) is), the 4 order comparisons, and (not) in. 'in' should be the
> only surprise and most confusing.
>>>> 1 < 3 in {3,4}
> True
>>>> 3 in {3,4} < {4}
> False
> 'and' and 'or' are not included because they do not always return a bool,
> and indeed, they are not binary operators in the usual sense because of
> short-circuiting.

The only one of those operators that can be said to always return a
bool is "is (not)".  The others (apart from "and" and "or") all can be
overloaded to return anything you want (for example, sqlalchemy
overloads them to return expression objects that are later compiled
into SQL), and chaining still occurs regardless of the types they are
applied to.

More information about the Python-list mailing list