[issue20859] Context of documentation for conditional expressions

2021-06-23 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

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

LGTM

> "Python evaluates expressions from left to right (except for conditional 
> expressions)."

LGTM. It would be nice to add also examples for conditional and assignment 
expressions.

> Should 'except for lambda' be added to the end of the sentence?

Yes, lambda and assignment expressions have lower priority.

--
nosy: +serhiy.storchaka

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue20859] Context of documentation for conditional expressions

2021-06-22 Thread Irit Katriel


Change by Irit Katriel :


--
versions: +Python 3.10, Python 3.11, Python 3.9 -Python 2.7, Python 3.3, Python 
3.4

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue20859] Context of documentation for conditional expressions

2014-05-09 Thread Ezio Melotti

Changes by Ezio Melotti ezio.melo...@gmail.com:


--
nosy: +ezio.melotti

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue20859
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue20859] Context of documentation for conditional expressions

2014-03-06 Thread Terry J. Reedy

New submission from Terry J. Reedy:

The documentation for conditional expressions (c_exps)
http://docs.python.org/3/reference/expressions.html#conditional-expressions
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
 0 if 1 else (0 if 0 else 1)
0
 (0 if 1 else 0) if 0 else 1
1

This sentence in the Operator Precedence section
http://docs.python.org/3/reference/expressions.html#operator-precedence

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.
http://docs.python.org/3/reference/expressions.html#evaluation-order
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.

--
messages: 212835
nosy: rhettinger, terry.reedy
priority: normal
severity: normal
stage: needs patch
status: open
title: Context of documentation for conditional expressions
type: behavior
versions: Python 2.7, Python 3.3, Python 3.4

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue20859
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com