-
Notifications
You must be signed in to change notification settings - Fork 160
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
Basic match statement support #291
Conversation
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 very polished PR! I only have one small comment, see below.
tests/test_scavenging.py
Outdated
check(v.defined_vars, ["RED", "YELLOW", "GREEN", "color"]) | ||
|
||
check(v.unused_classes, []) | ||
check(v.unused_vars, []) |
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.
Nice tests! Can you add one unused variable in each case, please? That is, a dataclass member that's not used in the match 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.
Thank you, I updated the test cases.
Codecov Report
@@ Coverage Diff @@
## main #291 +/- ##
=======================================
Coverage 99.38% 99.38%
=======================================
Files 19 19
Lines 647 651 +4
=======================================
+ Hits 643 647 +4
Misses 4 4
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
Great! Thanks @kreathon ! |
🤩 Awesome! Nice to see this addressed! Thanks, for taking up this issue @jendrikseipp & @kreathon ! |
Example
At the moment,
a
would be seen as unused. However, as nicely described by @exoriente, the code means something likeSo it is not a normal / dead "assignment" and
a
should not be seen as unused.Implementation
The actual code change is really trivial, since most of the desired behavior (for the match statement) is already handled by
visit_Name
:Limitations
__match_args__
are possible)case
: e.g. "case [1, a, *rest]" (a
andrest
is not handled i.e. checked if it is used in the case body). Currently, I do not see any problem implementing it in the future.Python Compatibility
For Python < 3.10 the
visit_MatchClass
should never be executed. Tests are guarded with@pytest.mark.skipif( sys.version_info < (3, 10), ...)
Related Issue
This PR is addressing the issue #276.
Checklist:
tox -e fix-style
to format my code and checked the result withtox -e style
.