-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Avoid reporting useless-suppression on wrong-import-position (#5219) #6347
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
Conversation
Pull Request Test Coverage Report for Build 2259016368
π - Coveralls |
|
Thanks for the PR. What do you think about this diff? A bit smaller. EDIT: never mind, looks like it fails a test. diff --git a/pylint/checkers/imports.py b/pylint/checkers/imports.py
index d90173c0..4fa01e02 100644
--- a/pylint/checkers/imports.py
+++ b/pylint/checkers/imports.py
@@ -503,6 +503,7 @@ class ImportsChecker(DeprecatedMixin, BaseChecker):
self._imports_stack = []
self._first_non_import_node = None
+ @check_messages(*MSGS)
def compute_first_non_import_node(self, node):
# if the node does not contain an import instruction, and if it is the
# first node of the module, keep a track of it (all the import positions
@@ -543,6 +544,7 @@ class ImportsChecker(DeprecatedMixin, BaseChecker):
visit_ifexp
) = visit_comprehension = visit_expr = visit_if = compute_first_non_import_node
+ @check_messages(*MSGS)
def visit_functiondef(self, node: nodes.FunctionDef) -> None:
# If it is the first non import instruction of the module, record it.
if self._first_non_import_node:
@@ -594,16 +596,7 @@ class ImportsChecker(DeprecatedMixin, BaseChecker):
# if a first non-import instruction has already been encountered,
# it means the import comes after it and therefore is not well placed
if self._first_non_import_node:
- if self.linter.is_message_enabled(
- "wrong-import-position", self._first_non_import_node.fromlineno
- ):
- self.add_message(
- "wrong-import-position", node=node, args=node.as_string()
- )
- else:
- self.linter.add_ignored_message(
- "wrong-import-position", node.fromlineno, node
- )
+ self.add_message("wrong-import-position", node=node, args=node.as_string())
def _record_import(self, node, importedmodnode):
"""Record the package `node` imports from.""" |
|
|
jacobtylerwalls
left a comment
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.
By the way, the test that failed with my smaller diff was the test in #1337. (Yes, 1337! π )
So I'm good with this approach, meaning we can still support that somewhat special case.
Do we understand why that test fails? It seems like it should work right? |
My understanding is that it's a really special case to extend the disable functionality. |
|
I don't have much to add, except to say that I was trying to change the logic of the check as little as possible while avoiding the If anyone thinks this needs a different approach I can take another run at it. |
Type of Changes
Description
With a suppressed
wrong-import-positionwarning anduseless-suppressionsenabled, Pylint was issuing auseless-suppressionwarning even though the suppression was not useless. This was happening because of a change here that fixed #1366; It was skipping the entire calculation of the checker when the warning was disabled, which prevents it from recording that the checker would have been hit. There's a similar fix here for the same case withwrong-import-order.Closes #5219