-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
gh-106780: Add __match_args__ to tutorial example #106784
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
Add Point definition with this attribute before example that needs it.
How about using dataclass or namedtuple with comment? |
@methane Class Point without the added line appears at line 309 followed by a match statement whose cases only use keyword matching. The paragraph that follow mentions using match_args to allow cases using positional matching. This augmented class and the match that follows illustrates this point. Without this, using the previous definition of Point, this example fails. So I consider this the proper fix for this issue. Note that the primary purpose of this example is to show nested patterns, in this case class(es) inside of a sequence. Showing positional matching is secondary. This is the tutorial and to me, namedtuples and dataclasses are a more advanced topic. (I have never used the latter.) I think they should be another issue. |
Thanks @terryjreedy for the PR 🌮🎉.. I'm working now to backport this PR to: 3.11, 3.12. |
GH-106819 is a backport of this pull request to the 3.12 branch. |
) Add Point definition with this attribute before example that needs it. (cherry picked from commit 7aa89e5) Co-authored-by: Terry Jan Reedy <[email protected]>
) Add Point definition with this attribute before example that needs it. (cherry picked from commit 7aa89e5) Co-authored-by: Terry Jan Reedy <[email protected]>
GH-106820 is a backport of this pull request to the 3.11 branch. |
…106819) Add Point definition with this attribute before example that needs it. (cherry picked from commit 7aa89e5) Co-authored-by: Terry Jan Reedy <[email protected]>
…106820) Add Point definition with this attribute before example that needs it. (cherry picked from commit 7aa89e5) Co-authored-by: Terry Jan Reedy <[email protected]>
Both of dataclasses and
I feel manually define Anyway, it is a matter of preference and either is acceptable. |
Add Point definition with this attribute before example that needs it.
📚 Documentation preview 📚: https://cpython-previews--106784.org.readthedocs.build/