-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
bpo-42128: Add documentation for pattern matching (PEP 634) #24664
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
Conversation
The tutorial is a slightly modified version of PEP-636 Appendix A
This reverts commit 6320747.
Co-Authored-By: Daniel F Moisset <[email protected]> Co-Authored-By: Guido van Rossum <[email protected]> Co-Authored-By: Brandt Bucher <[email protected]>
…DOs left) one table idea was inspired by Raymond's awesome tweet here https://twitter.com/raymondh/status/1361780586570948609 Co-Authored-By: Raymond Hettinger <[email protected]>
Co-authored-by: Daniel F Moisset <[email protected]>
Some minor typos, and copy/paste fixes
|
This is currently a Draft PR because I plan to make some minor adjustments, but it should be "complete" and reviewable at this point. The planned changes are likely to be some removals/rearranging of content in the "Doc/reference/compound_stmts.rst" file |
|
@dmoisset @Fidget-Spinner I assume that the two of you have co-authored this? Once you two agree that this is ready to be merged I will just merge it sight unseen -- I don't have time this weekend to do a full review, and I think it's important that we have docs to go with the code that @brandtbucher just landed. Note that the 3.10a6 release goes out Monday. |
Apart from the compound statements reference, I'm very happy with the changes (huge thanks to Daniel for writing the majority of the other parts!). We're currently trying to fine tune the compound statements reference because its quite long. If we can't make it in time for Monday, I'm OK with merging it as-is: we can always make more PRs to amend it later and the online docs auto rebuilds everyday anyways. Btw, please apply the skip news label if you feel it fits that :). Thanks! |
Co-authored-by: Ken Jin <[email protected]>
This avoid some possible confusion present in the previous language, where it wasn't explicit that bindings happened before the guard was valuated
Your assumption is correct. I flagged this as ready to merge (I hope @Fidget-Spinner agrees, I've ended up butchering the table but keeping the content... for people who wants a high-level overview, they can look at the tutorial or the PEP rather than the reference). I'm happy to refine if problems are found in review later on. |
gvanrossum
left a comment
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.
Thanks for this extensive work! I'll merge my two suggestions and then land it later tonight.
| consensus (yet) on whether and how to do range tests. See :pep:`275` for | ||
| complete details and the current status. | ||
| For literal values, or constants within a namespace, you can also use a | ||
| ``match ... case`` statement. |
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 expect it would be better to rewrite or remove this section, but not now. IMO "match" is the missing switch/case statement.
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.
Or update the question to be: Is there a switch or case statement in Python?
| ... | ||
|
|
||
|
|
||
| .. _tut-match: |
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.
Note that we now have two slightly diverging versions of the same introduction to match statements in the docs (three if you count Appendix A of PEP 636) -- the other is in what's new in 3.10. We don't have to fix this now but I think it would be good if the texts didn't arbitrarily differ from each other. Either the same text should be included in both places (possibly with a different intro and outro), or what's new should be much shorter and just point here. Again, doesn't need to be addressed today, but something to keep in mind. /CC @willingc
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.
It makes good sense to bring the two closer together. I would err on the side of clarity over length in the What's New as it's what most folks will read before or after the PEP tutorial.
willingc
left a comment
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.
Thanks @dmoisset. After the alpha goes out we can take a look at both this PR and the What's New again.
| consensus (yet) on whether and how to do range tests. See :pep:`275` for | ||
| complete details and the current status. | ||
| For literal values, or constants within a namespace, you can also use a | ||
| ``match ... case`` statement. |
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.
Or update the question to be: Is there a switch or case statement in Python?
| Some identifiers are only reserved under specific contexts. These are known as | ||
| *soft keywords*. The identifiers ``match``, ``case`` and ``_`` can | ||
| syntactically act as keywords in contexts related to the pattern matching | ||
| statement, but this distinction is done at the parser level, not when |
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.
Good description.
| ... | ||
|
|
||
|
|
||
| .. _tut-match: |
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.
It makes good sense to bring the two closer together. I would err on the side of clarity over length in the What's New as it's what most folks will read before or after the PEP tutorial.
Co-authored-by: Carol Willing <[email protected]>
|
I will land this tonight once the tests pass. |
|
@gvanrossum: Please replace |
This covers documentation for the new match statement in 3.10, as requested by the SC in https://mail.python.org/archives/list/[email protected]/message/SQC2FTLFV5A7DV7RCEAR2I2IKJKGK7W3/
The documentation includes:
__match_args__https://bugs.python.org/issue42128