Skip to content

bpo-45619: documentation of execution model: clarify and update binding summary #29232

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

Merged
merged 2 commits into from
Nov 26, 2021

Conversation

Arthur-Milchior
Copy link
Contributor

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

bpo-45619: updating and improving the list of bindings

This does three changes that are quite related.

  1. It breaks a long sentence enumerating things into a list
  2. it adds two missing elements to the list:
    a. assignment-expression can also bind a value. This should have been updated in 3.8.
    b. variable binding can occur in pattern matching, an update of 3.10

This PR would be relevant in 3.8 and 3.9, except obviously for the pattern matching part. However, I understand that is not critical and can't be easily cherry-picked, so I assume it won't be backported.

https://bugs.python.org/issue45619

@bedevere-bot bedevere-bot added the docs Documentation in the Doc dir label Oct 27, 2021
* class and function definitions (these bind the class or function name in the
defining block),
* and targets that are identifiers:
+ if occurring in an assignment,
Copy link
Member

Choose a reason for hiding this comment

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

Honestly I think assignment expressions should be a separate bullet (as you said you considered in the PR description). Also, I think it should go above here, because the LHS of a walrus is not a target -- it's a plain name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I do not know what is the exact definition of a target (even if I can guess from context), and I can't easily find such a definition in the documentation. If it is defined somewhere formally, I'd argue to link to it. Otherwise, seems a good place to define it.

Copy link
Member

Choose a reason for hiding this comment

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

@Arthur-Milchior
Copy link
Contributor Author

Also, it will probably need the skip-news label. But I can't add it myself.

Copy link
Member

@gvanrossum gvanrossum left a comment

Choose a reason for hiding this comment

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

I think we should make these tiny fixes and then consider it good enough to merge. I’ll wait a bit for others to pipe up though.

@gvanrossum gvanrossum changed the title bpo-45619: documentation of execution model: pattern matching bpo-45619: documentation of execution model: clarify and update binding summary Oct 27, 2021
@gvanrossum
Copy link
Member

Can you add the link to ‘target’?

@gvanrossum
Copy link
Member

Can you fix the test errors? (You can run the doc build process locally to experiment until it passes. IIRC there’s a README in the Doc directory.)

@Arthur-Milchior
Copy link
Contributor Author

Arthur-Milchior commented Oct 27, 2021

I don't see how to add a link to target. For two reasons. First I need a plural and links seems to only work for singular. Secondly, the examples I find are keywords, but target is not a keyword. And since it seems that it is a Python specific role, I can't directly find a detailed description in sphinx documentation.

I did try to run. However,
make venv
make html
leads to

make html
mkdir -p build
Building NEWS from Misc/NEWS.d with blurb
PATH=./venv/bin:$PATH sphinx-build -b html -d build/doctrees -W . build/html
Running Sphinx v3.2.1

Warning, treated as error:
node class 'meta' is already registered, its visitors will be overridden
make: *** [Makefile:51: build] Error 2

The error message is really sparse, making it hard to actually debug. I'll however check the git error message hoping it will help understanding.

@gvanrossum
Copy link
Member

Seems the docs pipeline is wedged due to a new release of docutils(?). Let’s forget about the link.

P.S. There is no need to squash commits, we do that at the end when we merge.

@gvanrossum
Copy link
Member

If you merge/rebase the latest main, the doc build should be fixed. I'd like to make sure this passes before merging. Thanks!

Comment on lines 69 to 73
+ in a capture pattern in structural pattern matching
* :keyword:`import` statements.
Copy link
Member

Choose a reason for hiding this comment

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

I'm guessing you need a blank line after the interior bullet list? That might render ugly, but we can't keep the warning on the next line. But I'm not a ReST expert. :-(

@Arthur-Milchior
Copy link
Contributor Author

I confirm that, after rebasing, I can now compile it. I'm new to Sphinx, but I'm confident I can now correct it quickly, thanks to clear error message

@Arthur-Milchior
Copy link
Contributor Author

Done. The result looks like the attached image
2021-10-28-044637_767x241_scrot

and the link works. It goes to target the production rule. It may have been better that it go to the paragraph above, but honestly, I don't understand how this is supposed to work. I tried to search for example of reference to paragraph declared with index but I failed to find any reference between files that work.

Given that it still works and is a progress, I am confortable with merging it (being able to test the result also help a lot my confidence.)
In any case, it is not clear to me how I was supposed to use the link you gave me, given that Sphinx uses special syntax to create internal link.

@terryjreedy
Copy link
Member

#29183 has this markup for a cross-doc link.

:meth:`x.__trunc__ <object.__trunc__>`

It links the library/math truncate entry to the reference/data_model object.trunc entry. This must depend on some global uniqueness.
@merwok Do you happen to know how to link target in this PR's revision to the reference execution-model chapter to https://docs.python.org/3/reference/simple_stmts.html#grammar-token-python-grammar-target?

@merwok
Copy link
Member

merwok commented Nov 3, 2021

That format is:

.. reference with custom text
:role:`free text <reference>`

.. short version, the text of the link is determined by the target:

:role:`reference`

reference must be a valid target, which can be created by various markup including .. _target: before a title (IIRC), .. class::, .. function:: and other similar directives, and .. index::. role is in general specific (class, func, meth, cmdoption but in truth most (all?) of these use a common namespace and so are exchangeable).

I hadn’t noticed the productionlist directive before this PR; documentation at https://devguide.python.org/documenting/#grammar-production-displays suggests that targets are created, but doesn’t make their format explicit, so I don’t know what target to use.

@merwok
Copy link
Member

merwok commented Nov 3, 2021

Found the reference: https://www.sphinx-doc.org/en/master/usage/restructuredtext/directives.html#directive-productionlist

So it should be:

:token:`target` or :token:`targets <target>` for a plural

@Arthur-Milchior
Copy link
Contributor Author

I just noticed I pushed two commits by accident. The first has nothing to do in this PR, trunc is already considered in another PR. Is it okay if I remove it and force push to keep only relevant commit ? Or do you want me to push a commit reverting the first commit ?

@gvanrossum
Copy link
Member

For this situation a force-push is fine.

This does two changes that are quite related.

0. it add that variable binding can occur in pattern matching, an update of 3.10
which seems to have been omitted from the list of bindings
1. Given how long the sentence alrady was, with even subcases in the middle of
the sentence, the commit breaks the sentence into an actual list.
@Arthur-Milchior
Copy link
Contributor Author

Done. I removed the commit that should not have been here.

#29183 has this markup for a cross-doc link.

:meth:`x.__trunc__ <object.__trunc__>`

It links the library/math truncate entry to the reference/data_model object.trunc entry. This must depend on some global uniqueness. @merwok Do you happen to know how to link target in this PR's revision to the reference execution-model chapter to https://docs.python.org/3/reference/simple_stmts.html#grammar-token-python-grammar-target?

I suspect this is not relevant anymore for this PR.
It may have been relevant for d9c1868 that is already merged, and so may need another PR to update to the correct form if this one is not correct.

@merwok
Copy link
Member

merwok commented Nov 3, 2021

I am not so sure 🙂 that sub-discussion was prompted by this comment that’s relevant to this PR:

and the link works. It goes to target the production rule. It may have been better that it go to the paragraph above, but honestly, I don't understand how this is supposed to work. I tried to search for example of reference to paragraph declared with index but I failed to find any reference between files that work.

I replied to Terry’s question about linking to grammar tokens (re-discovering the markup that you had already used in fact), and can also answer your question:

:ref:`assignment`

.. or to control link text
:ref:`targets <assignment>`

should create a link to the heading you want. This line defines the target: https://github.com/python/cpython/blob/3.10/Doc/reference/simple_stmts.rst#L69

About index: they don’t reuse human-defined targets but create their own, such as https://docs.python.org/3.10/reference/simple_stmts.html#index-4 (example link reached from assignment expression [1] (click on [1]) on https://docs.python.org/3.10/genindex-A.html — I agree index is not the easiest directive to understand!)

@gvanrossum
Copy link
Member

Hopefully @merwok and @terryjreedy can finish reviewing this PR? I need to focus elsewhere.

@gvanrossum gvanrossum requested a review from merwok November 3, 2021 04:23
@Arthur-Milchior
Copy link
Contributor Author

I just updated "targets" to be a link to the entry "assignment". I hope this ensure that the PR can now be approved. I'm not really sure whether "assignment" section or "token" literal is better; personally I'm totally fine with both. I used the latter because I thought it was what was asked, I beg your pardon for misunderstanding.

I edited the PR first message to update it with what is now actually in the PR.

Copy link
Member

@gvanrossum gvanrossum left a comment

Choose a reason for hiding this comment

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

I think this is a sufficient improvement over what we have to merge the PR. However, I think this is an example of why our "reference" manual is too imprecise to be considered a language specification. Alas, it would take a committee of 10 people 10 years to come up with an adequate specification, and we just don't have those resources. So this will have to do.

@gvanrossum gvanrossum merged commit cd876c8 into python:main Nov 26, 2021
@miss-islington
Copy link
Contributor

Thanks @Arthur-Milchior for the PR, and @gvanrossum for merging it 🌮🎉.. I'm working now to backport this PR to: 3.10.
🐍🍒⛏🤖 I'm not a witch! I'm not a witch!

@bedevere-bot
Copy link

@gvanrossum: Please replace # with GH- in the commit message next time. Thanks!

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Nov 26, 2021
…ng summary (pythonGH-29232)

This does two changes that are quite related.

0. it add that variable binding can occur in pattern matching, an update of 3.10
which seems to have been omitted from the list of bindings
1. Given how long the sentence already was, with even subcases in the middle of
the sentence, the commit breaks the sentence into an actual list.
(cherry picked from commit cd876c8)

Co-authored-by: Arthur Milchior <[email protected]>
@bedevere-bot
Copy link

GH-29787 is a backport of this pull request to the 3.10 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.10 only security fixes label Nov 26, 2021
miss-islington added a commit that referenced this pull request Nov 26, 2021
…ng summary (GH-29232)

This does two changes that are quite related.

0. it add that variable binding can occur in pattern matching, an update of 3.10
which seems to have been omitted from the list of bindings
1. Given how long the sentence already was, with even subcases in the middle of
the sentence, the commit breaks the sentence into an actual list.
(cherry picked from commit cd876c8)

Co-authored-by: Arthur Milchior <[email protected]>
@Arthur-Milchior Arthur-Milchior deleted the case_binding branch November 26, 2021 12:49
remykarem pushed a commit to remykarem/cpython that referenced this pull request Dec 7, 2021
…ng summary (python#29232)

This does two changes that are quite related.

0. it add that variable binding can occur in pattern matching, an update of 3.10
which seems to have been omitted from the list of bindings
1. Given how long the sentence already was, with even subcases in the middle of
the sentence, the commit breaks the sentence into an actual list.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir skip news
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants