-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
missing dataclass decorator in match-statement example #88275
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
Comments
Using Point class as in the documentation example, raises TypeError: Point() takes no arguments Also there is same example in the PEP-636's latests parts, Point class used with dataclass decorator and works perfectly. |
I don't really think there is anything wrong with the documentation. I can copy-and-paste all of the code from the PEP-634 section of the 3.10 What's New into the REPL without any issues (provided that named subjects like point/points/test_variable/color are actually defined). Note that none of the example snippets actually *create* Point instances. Rather, some of the patterns *match* Point instances... which is sort of the opposite of instantiation. As the Point class is currently written, instantiation would probably look like:
Sure, it would help to have an __init__ defined in real code, but I sort of feel like adding it to this example would just distract (especially since the example doesn't actually *need* it). Thoughts from others? |
As it stands, the Point class is weird and atypical by only using class variables. The example would be improved by adding @DataClass or inheriting from typing.NamedTuple. |
I agree with Raymond: a more useful example would use dataclasses or typing.NamedTuple. The use of class variables is unusual, and it took me a while to understand how it would work. |
I agree the example is confusing for all of the stated reasons. It seems to me it's better to use a plain class with a
I can make a PR that adds |
Ahmet: once there's agreement on how to fix this, would you like to work on a patch? |
We have a similar example in https://docs.python.org/3.12/tutorial/controlflow.html#match-statements, which is define the |
…honGH-120281) (cherry picked from commit 7a9d462) Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>
…honGH-120281) (cherry picked from commit 7a9d462) Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
Linked PRs
__init__
method to the example #120281__init__
method tomatch
example (GH-120281) #134142__init__
method tomatch
example (GH-120281) #134143The text was updated successfully, but these errors were encountered: