Skip to content

Conversation

@dmoisset
Copy link
Contributor

@dmoisset dmoisset commented Feb 27, 2021

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:

  • A large language reference update include syntax and behaviour of the match statement, largely based on the relevant sections of PEP-634 in the compound statements section.
  • A significant new section in the "control flow" chapter of the tutorial based on the Appendix A of PEP-636
  • An update to the "data model" reference chapter describing the new special attribute __match_args__
  • A new section in the "lexical analysis" chapter describing the use of soft keywords.
  • An update to the FAQ entry about "Why isn't there a switch or case statement in Python?"

https://bugs.python.org/issue42128

dmoisset and others added 21 commits February 27, 2021 23:33
The tutorial is a slightly modified version of PEP-636 Appendix A
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]>
Some minor typos, and copy/paste fixes
@dmoisset
Copy link
Contributor Author

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

@gvanrossum
Copy link
Member

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

@Fidget-Spinner
Copy link
Member

@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

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!

@dmoisset dmoisset marked this pull request as ready for review February 28, 2021 23:44
@dmoisset
Copy link
Contributor Author

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

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.

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.

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

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.

Copy link
Contributor

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

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

Copy link
Contributor

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.

Copy link
Contributor

@willingc willingc left a 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.
Copy link
Contributor

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
Copy link
Contributor

Choose a reason for hiding this comment

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

Good description.

...


.. _tut-match:
Copy link
Contributor

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]>
@gvanrossum
Copy link
Member

I will land this tonight once the tests pass.

@gvanrossum gvanrossum merged commit a22bca6 into python:master Mar 1, 2021
@bedevere-bot
Copy link

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

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.

6 participants