-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Misc cleanup #10580
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
Misc cleanup #10580
Conversation
Add new checks for invalid uses of class patterns in :keyword:`match`. | ||
* :ref:`invalid-match-args-definition` is emitted if :py:data:`object.__match_args__` isn't a tuple of strings. | ||
* :ref:`too-many-positional-sub-patterns` if there are more positional sub-patterns than specified in :py:data:`object.__match_args__`. | ||
* :ref:`multiple-class-sub-patterns` if there are multiple sub-patterns for the same attribute. |
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.
Ref #10559
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.
Did you see #10568 ?
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.
Yes. It looks quite promising though I only skimmed through it so far.
I only modified these here since I added the new checks just before adding the first refs.
case nodes.Tuple(elts=elts) if len(elts) > 0: | ||
self.add_message("assert-on-tuple", node=node, confidence=HIGH) | ||
case nodes.Const(value=str(val)): | ||
case nodes.Const(value=str() as val): |
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.
I do plan to add a checker for these soon.
import astroid | ||
import astroid.bases |
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.
astroid.bases
is referenced in this file. It doesn't fail currently likely because other files also import it. Just add it here as well for good measure.
from typing import TYPE_CHECKING, Any, NamedTuple, TypeAlias | ||
|
||
import astroid | ||
import astroid.objects |
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.
Same here.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #10580 +/- ##
==========================================
- Coverage 95.93% 95.93% -0.01%
==========================================
Files 176 176
Lines 19471 19470 -1
==========================================
- Hits 18679 18678 -1
Misses 792 792
🚀 New features to boost your workflow:
|
This comment has been minimized.
This comment has been minimized.
) and all(self._is_node_return_ended(_child) for _child in handlers) | ||
case nodes.Assert(test=nodes.Const(value=value)) if not value: | ||
case nodes.Assert(test=nodes.Const(value=False | 0)): | ||
# consider assert False as a return node | ||
return True |
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.
Guess it's not enough to handle just assert False
. Pytest also uses assert 0
. Technically assert None
or assert ""
and similar could also be used, though I don't think they are common enough.
🤖 According to the primer, this change has no effect on the checked open source code. 🤖🎉 This comment was generated for commit a78c2bf |
Misc cleanup after match PRs and other minor changes.