-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add unreachable-match-patterns
message and new checker.
#10424
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? # to your account
base: main
Are you sure you want to change the base?
Add unreachable-match-patterns
message and new checker.
#10424
Conversation
Codecov ReportAll modified and coverable lines are covered by tests β
Additional details and impacted files@@ Coverage Diff @@
## main #10424 +/- ##
=======================================
Coverage 95.86% 95.87%
=======================================
Files 175 177 +2
Lines 19074 19153 +79
=======================================
+ Hits 18286 18363 +77
- Misses 788 790 +2
π New features to boost your workflow:
|
``unreachable-match-patterns``. This will emit an error message when a name capture pattern is used in a match statement which would make the remaining patterns unreachable. This code is a SyntaxError at runtime. Closes pylint-dev#7128
f1ca097
to
0e5ef7c
Compare
remaining-patterns-unreachable
checker.unreachable-match-patterns
message and new checker.
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 check!
and case.pattern.pattern is None | ||
and isinstance(case.pattern.name, nodes.AssignName) | ||
and idx < len(node.cases) - 1 | ||
and self._py310_plus |
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.
Why check the version? Shouldn't this always be checked if we find these patterns?
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.
Why check the version?
My mistake. We shouldn't check it. I must have been thinking that this line would prevent an error from occurring if Pylint was run in an environment using Python 3.9 or lower since the match statement (and the ast.Match node) is only available in Python 3.10 and higher.
The solution would be to remove this line and wait until Python 3.9 is end of life before considering a merge?
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.
Seems very sensible to me!
Type of Changes
Description
This will emit an error message when a name capture pattern is used in a match statement which would make the remaining patterns unreachable. This code is a SyntaxError at runtime.
Closes #7128