Skip to content

Conversation

mas192
Copy link

@mas192 mas192 commented May 19, 2024

@ghost
Copy link

ghost commented May 19, 2024

All commit authors signed the Contributor License Agreement.
CLA signed

@bedevere-app bedevere-app bot added docs Documentation in the Doc dir skip news awaiting review labels May 19, 2024
@mas192 mas192 changed the title Revised conditional expression with additional context and examples for issue #65058 gh-65058 Revised conditional expression with additional context and examples for issue May 19, 2024
their suffixes::
their suffixes:

.. code-block:: python
Copy link
Contributor

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.

Copy link
Author

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?

Copy link
Contributor

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 ::.

Copy link
Author

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!

Copy link
Contributor

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.

Copy link
Author

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

Copy link
Member

@picnixz picnixz Oct 5, 2024

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.

@nineteendo
Copy link
Contributor

You should only merge with master to fix merge conflicts, or if you need something that was just added.

@mas192
Copy link
Author

mas192 commented May 20, 2024

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:
Copy link
Member

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).
Copy link
Member

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.

Copy link
Contributor

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.9435486122336787

Copy link
Member

@vadmium vadmium Oct 5, 2024

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'
Copy link
Member

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:
Copy link
Member

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)
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting review docs Documentation in the Doc dir skip news
Projects
Status: Todo
Development

Successfully merging this pull request may close these issues.

5 participants