This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author tim.peters
Recipients sangeetamchauhan, steven.daprano, tim.peters
Date 2019-09-10.16:49:39
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1568134179.42.0.739555265669.issue38060@roundup.psfhosted.org>
In-reply-to
Content
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.
History
Date User Action Args
2019-09-10 16:49:39tim.peterssetrecipients: + tim.peters, steven.daprano, sangeetamchauhan
2019-09-10 16:49:39tim.peterssetmessageid: <1568134179.42.0.739555265669.issue38060@roundup.psfhosted.org>
2019-09-10 16:49:39tim.peterslinkissue38060 messages
2019-09-10 16:49:39tim.peterscreate