-
-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
Add new checks for invalid uses of class patterns in ``match``. | ||
* ``invalid-match-args-definition`` is emitted if ``__match_args__`` isn't a tuple of strings. | ||
* ``too-many-positional-sub-patterns`` if there are more positional sub-patterns than specified in ``__match_args__``. | ||
* ``multiple-class-sub-patterns`` if there are multiple sub-patterns for the same attribute. | ||
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. | ||
|
||
Refs #10559 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -717,7 +717,7 @@ def visit_assert(self, node: nodes.Assert) -> None: | |
match node.test: | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. I do plan to add a checker for these soon. |
||
when = "never" if val else "always" | ||
self.add_message("assert-on-string-literal", node=node, args=(when,)) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
from typing import TYPE_CHECKING | ||
|
||
import astroid | ||
import astroid.bases | ||
Comment on lines
19
to
+20
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
from astroid import nodes | ||
from astroid.typing import InferenceResult | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
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 commentThe reason will be displayed to describe this comment to others. Learn more. Same here. |
||
from astroid import bases, nodes, util | ||
from astroid.nodes import LocalsDictNodeNG | ||
from astroid.typing import SuccessfulInferenceResult | ||
|
@@ -1641,7 +1642,7 @@ def _check_slots_elt( | |
match inferred: | ||
case util.UninferableBase(): | ||
continue | ||
case nodes.Const(value=str(value)) if value: | ||
case nodes.Const(value=str() as value) if value: | ||
pass | ||
case _: | ||
self.add_message( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
from typing import TYPE_CHECKING, Any, NamedTuple, TypeAlias, cast | ||
|
||
import astroid | ||
import astroid.objects | ||
from astroid import bases, nodes | ||
from astroid.util import UninferableBase | ||
|
||
|
@@ -1125,7 +1126,6 @@ def _check_consider_using_generator(self, node: nodes.Call) -> None: | |
inside_comp = f"({inside_comp})" | ||
inside_comp += ", " | ||
inside_comp += ", ".join(kw.as_string() for kw in node.keywords) | ||
call_name = node.func.name | ||
if call_name in {"any", "all"}: | ||
self.add_message( | ||
"use-a-generator", | ||
|
@@ -2043,7 +2043,7 @@ def _is_node_return_ended(self, node: nodes.NodeNG) -> bool: | |
return any( | ||
self._is_node_return_ended(_child) for _child in all_but_handler | ||
) 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 | ||
Comment on lines
-2046
to
2048
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Guess it's not enough to handle just |
||
# recurses on the children of the node | ||
|
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 ?
Uh oh!
There was an error while loading. Please reload this page.
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.