Skip to content
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

bpo-45646: clarifying the meaning of expression #29303

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Arthur-Milchior
Copy link
Contributor

@Arthur-Milchior Arthur-Milchior commented Oct 29, 2021

#bpo-45646: clarifying the meaning of expression

Expression rules are quite confusing. For example x & y is a "or_expr". This
makes sens only if you understand that "or_expr" means "you can use an | here,
and potentially other things" instead of "an expression using |" which is the
intuitive meaning.

I check my intuition on #help-broccoli on Python channel, and it seems that
multiple helpers were as confused as myself when they discovered that
list comprehension used or_expr according to the syntax, while | is not usually
defined on list.

This edit expects to ensure future reader do not make the same mistake I did
while reading chapter 6 of the reference. Furthermore, it provides an example of
the syntax note, which, I hope, will help clarify it.

https://bugs.python.org/issue45646

Expression rules are quite confusing. For example `x & y` is a "or_expr". This
makes sens only if you understand that "or_expr" means "you can use an | here,
and potentially other things" instead of "an expression using |" which is the
intuitive meaning.

I check my intuition on #help-broccoli on Python channel, and it seems that
multiple helpers were as confused as myself when they discovered that
list comprehension used or_expr according to the syntax, while | is not usually
defined on list.

This edit expects to ensure future reader do not make the same mistake I did
while reading chapter 6 of the reference. Furthermore, it provides an example of
the syntax note, which, I hope, will help clarify it.
This rewritting was provided by Dennis Sweeney (@sweeneyde), with a few changes
and Sphinx syntax by me.

The only purpose of using `grammar-example` is to ensure that the usual
a_expr token is distinct from the example one. So that links can decide whether
they points to the example or to the explanation of a_expr

I was not able to get m_expr to be a link. According to the doc,
`~python-grammar:m_expr` should suffice to link to python-grammar's rule for
m_expr. However, after testing, it was just displayed as
"~python-grammar:m_expr" (and I checked, it was compiled with sphinx 4.2.0)
@Arthur-Milchior
Copy link
Contributor Author

Rewritten, thanks to @sweeneyde

Main difficulty was to ensure that a_expr in the example is not actually used. So that when the documentation links to a_expr, it links to the non-example one, with the actual explanation. For this, I had to use a new scope grammar-example.

I've got a slight problem. I want the link to m_expr to link to the usual m_expr. According to Sphinx documentation it is possible https://www.sphinx-doc.org/en/master/usage/restructuredtext/directives.html#directive-productionlist
but actually, ~python-grammar:m_expr did not work and was displayed as "python-grammar:m_expr". I'd love help from someone good at sphinx. Or I guess it can be merged as is, it's not a bug, still understandable.

I rebased onto master to use the very recent dependency update of sphinx to 4.2.0. However, I kept the previous commit for history purpose as requested in other PR

@Arthur-Milchior
Copy link
Contributor Author

Could someone add "skip news" label, please? Because it's the only cause of failure of tests.

Copy link
Member

@sweeneyde sweeneyde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My apologies that this PR was left for so long. I still believe it can make a meaningful improvement.

Also, could you please git merge the main branch into this branch to make sure everything is up-to-date? That entails something like

git checkout expression
git fetch upstream main      # assuming upstream points as python/cpython
git merge upstream/main
git push origin expressions  # assuming origin is Arthur-Milchior/cpython

instances of :token:`~python-grammar:m_expr`, the rule implies that ``x * y``,
``x / y + a[i]``, and (recursively) ``foo.bar + x * y - a[i]`` are all instances
of :token:`~grammar-example:a_expr`. Unless specified otherwise, the semantic of
all of those expressions considered as an :token:`~grammar-example:a_expr` is
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all of those expressions

I think the above is ambiguous. It may be more clear to say something like

The semantics of x * y as an a_expr are the same as its semantics as an m_expr, and the same holds for other "pass-through" rules unless otherwise specified.

@@ -10,14 +10,28 @@ Expressions
This chapter explains the meaning of the elements of expressions in Python.

**Syntax Notes:** In this and the following chapters, extended BNF notation will
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

6 participants