Message351727
Ah, so you were expecting an error! That helps.
But that's not how the language works, or how it's documented to work, as has been explained in quite some detail already.
In general, precedence _constrains_ evaluation order, but does not _define_ it. In Python or any other language. In
9 or 7 > "str"
the precedence rules say the expression groups as
9 or (7 > "str")
rather than as, say,
(9 or 7) > "str"
but says nothing more than just that. It's a very intentional - and documented - feature of "and" and "or" that they do NOT evaluate their right-hand operands at all if the result of evaluating the left-hand operand first is enough to settle the issue. The precedence rules only define what the "left-hand" and "right-hand" operand expressions _are_.
I don't think the docs could be materially clearer about this. For example, from section "6.11. Boolean operations":
"""
The expression `x or y` first evaluates x; if x is true, its value is returned; otherwise, y is evaluated and the resulting value is returned.
"""
Precedence rules alone are too feeble to capture that. |
|
Date |
User |
Action |
Args |
2019-09-10 16:49:39 | tim.peters | set | recipients:
+ tim.peters, steven.daprano, sangeetamchauhan |
2019-09-10 16:49:39 | tim.peters | set | messageid: <1568134179.42.0.739555265669.issue38060@roundup.psfhosted.org> |
2019-09-10 16:49:39 | tim.peters | link | issue38060 messages |
2019-09-10 16:49:39 | tim.peters | create | |
|