-
-
Notifications
You must be signed in to change notification settings - Fork 33k
gh-65058 Revised conditional expression with additional context and examples for issue #119171
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…r right to left precedence
| their suffixes:: | ||
| their suffixes: | ||
|
|
||
| .. code-block:: python |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can just keep the ::, it automatically creates a code block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A explicit code block has better emphasis compared to to the :
Additionally too keep it consistent with the examples I wrote above 1927 I assumed its worth changing line 1927 too.
If you think is not needed should I revise and push again?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only 18 files use .. code-block:: python, while 460 use ::. So, I think it's best to use ::.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for pointing out to the inconsistencies. Since, .. code-block:: python
has better emphasis overall compared to ::
I don't mind refactoring all the 460 instances of ::
that said I would like to hear from a member of cpython team as well on the best course of action!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... just use ::. The indented block is clear enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The original pr I made was for adding examples and clarity to the documentation. I will wait for a member to review and approve or comment on that before I make any more changes. Thanks for the feedback
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally, I prefer .. code-block:: python when the snippets are long enough or if I don't want a colon to open my code-block (in this case, I however would prefer to keep a smaller diff since the changes are only cosmetics and we prefer not having cosmetic changes).
There is a difference between :: and .. code-block:: python. The first one uses the default highlighting and automatically adds a colon at the end of the sentence, namely this makes
Hello::
...equivalent to
Hello:
.. code-block::
...See https://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html#literal-blocks.
|
You should only merge with master to fix merge conflicts, or if you need something that was just added. |
|
got it thanks |
| Notice that while evaluating an assignment, the right-hand side is evaluated before | ||
| the left-hand side. | ||
|
|
||
| Examples for left to right: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps “Example [singular] of left-to-right grouping 1�7?
|
|
||
| Python evaluates expressions from left to right. Notice that while evaluating | ||
| an assignment, the right-hand side is evaluated before the left-hand side. | ||
| Python evaluates expressions from left to right (except for conditional_expression). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everywhere else the existing text just refers to them as conditional expressions in plural and without the underscore.
I’m not sure pointing out conditional expressions as the only exception is much better. Perhaps it should be except for conditional and exponentiation expressions?.
I think this sentence confuses the usage of evaluates. Perhaps we actually mean groups expressions? Compare the use of evaluate in the next sentence, meaning finding the value of operands. But then we’d be just repeating the “Operators . . . group 1�7 sentence in from the next section. Otherwise, see Terry’s 2nd point in #65058, about evaluating the middle first.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps it should be except for conditional and exponentiation expressions?
Why do you think so?
>>> class A:
... def __add__(self, other):
... print("Hi, from A!")
... return 1.23
... class B:
... def __add__(self, other):
... print("Hi, from B!")
... return 3.21
...
>>> (A() + A())**(B() + B())
Hi, from A!
Hi, from B!
1.9435486122336787There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah sorry I was confused. Perhaps the “left to right except conditional 1�7 got me thinking “conditional expressions must be the opposite, right to left 1�7 and therefore we must be talking about grouping, not evaluation.
| .. code-block:: python | ||
| 'foo' if 1 else 'bar' if 0 else 'baz' | ||
| 'foo' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if these would be clearer if they included the interactive prompt >>>
| 2 + 3 * 4 / 2 - 1 | ||
| 7 | ||
| Following is an example of right to left conditional_expression evaluation example: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Example of right-to-left conditional expression grouping
| comparisons, including tests, exponentiation and conditional expressions, which | ||
| group from right to left which all have the same precedence and chain from left | ||
| to right 1�7 see section Comparisons 1�7 and exponentiation, which groups from right | ||
| to left) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exponentiation listed twice. The exceptions don’t all have the same precedence. Partially redundant with the paragraph below.
…r right to left precedence
📚 Documentation preview 📚: https://cpython-previews--119171.org.readthedocs.build/