foo() is NOT defined.
>>> 0 and foo() (1)
0 # trivial
>>> 0 and foo() or 1 (2) # expecting it as 0 and (foo() or 1)
1 # does NOT short-circuit on 0
>>> 1 or foo() (3) # trivial
1
>>> 1 or foo() and 0 (4) # expecting it as 1 or (foo() and 0)
1 # DOES short-circuit on 1
I don’t see a consistent behavior from (2) and (4).
CASE 1
if we go by (2)’s evaluation style:
0 and foo() or 1
false or true (1)
true (1)
then I expect (4) as:
1 or foo() and 0
true and false (0)
false (0)
CASE 2
if we go by (4)’s evaluation style:
1 or foo() and 0
true or ...
true (1)
then I expect (2) as:
0 and foo() or 1
false and ...
false (0)
andhas higher precedence thanor.(2)
(4)