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 terry.reedy
Recipients rhettinger, terry.reedy
Date 2014-03-06.18:47:59
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
The documentation for conditional expressions (c_exps)
and the later sections on evaluation order and operator precedence have 3 inconsistencies with each other. I believe the latter (the 'context' of the title) were not properly adjusted with the addition of the former to match the exceptional behavior of c_exps.

1. Associativily-grouping: I believe the grammar line
  conditional_expression ::=  or_test ["if" or_test "else" expression]
makes c_exps group right to left, as in C.  Something like
  conditional_expression ::=  expression ["if" or_test "else" or_test]
would have the opposite effect. The following examples posted on python-list by 'candide' illustrate and verify.

>>> 0 if 1 else 0 if 0 else 1
>>> 0 if 1 else (0 if 0 else 1)
>>> (0 if 1 else 0) if 0 else 1

This sentence in the Operator Precedence section

"Operators in the same box group left to right (except for comparisons, including tests, which all have the same precedence and chain from left to right — see section Comparisons — and exponentiation, which groups from right to left)."

should have the last part revised to

"and exponentiation and conditional expressions, which group from right to left".

Perhaps a sentence and example should also be added to the C-E section also.

2. Evaluation Order: Condition expressions evaluate the middle subexpession first, making 
"Python evaluates expressions from left to right."
wrong as is, without noting the exception of c_exps.

I think "Except for conditional expressions, python evaluates expressions from left to right." gives too much weight to the exception.

"Python evaluates expressions from left to right (except for conditional expressions)." is a bit more awkward, but, appropriately, makes the exception more like a footnote.

3. Precedence: "Conditional expressions (sometimes called a “ternary operator”) have the lowest priority of all Python operations." versus the table, which lists lambda as lowest priority.  Should 'except for lambda' be added to the end of the sentence?  Should the top two lines of the table be reversed?  I do not know which is true, or perhaps neither. I get the impression from the grammar and the discussion in PEP308 that there are sort-of at the same level. Raymond, I add you as a PEP author particularly for this question.
Date User Action Args
2014-03-06 18:48:00terry.reedysetrecipients: + terry.reedy, rhettinger
2014-03-06 18:48:00terry.reedysetmessageid: <>
2014-03-06 18:48:00terry.reedylinkissue20859 messages
2014-03-06 18:47:59terry.reedycreate