On 7/14/2012 5:26 AM, Ian Kelly wrote:
On Fri, Jul 13, 2012 at 5:09 PM, Terry Reedy <tjre...@udel.edu> wrote:
I believe the following rule is true: if a op b is True or False raises,
Sorry, left out 'or' in 'or raises'
I don't follow. Raises what?
an Exception.
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
OK, add 'by default, without over-rides ;-).
or 'for builtin classes'.
Python's flexibility makes it really hard to make any general statement.
In my book-in-progress, I am currently resorting to saying "In Python*,
..." whenever I know and remember that it is possibly to over-ride the
customary behavior described in '...'.
--
Terry Jan Reedy
--
http://mail.python.org/mailman/listinfo/python-list