Skip to content
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

False negative for relative-beyond-top-level because pylint does not add warning on node properly #4852

Closed
Pierre-Sassoulas opened this issue Aug 15, 2021 · 1 comment
Labels
Bug 🪲 False Negative 🦋 No message is emitted but something is wrong with the code

Comments

@Pierre-Sassoulas
Copy link
Member

Pierre-Sassoulas commented Aug 15, 2021

Bug description

In #4848 when fixing the crash for #4775 it seems that the right message is not raised here

It's strange because the message should be raised (add_message is launched), but the node is probably not correct enough to be raised upon.

Using the following changes in pylint's code:

diff --git a/pylint/checkers/base_checker.py b/pylint/checkers/base_checker.py
index 4b220f28..aa9246af 100644
--- a/pylint/checkers/base_checker.py
+++ b/pylint/checkers/base_checker.py
@@ -108,6 +108,7 @@ class BaseChecker(OptionsProviderMixIn):
     ):
         if not confidence:
             confidence = UNDEFINED
+        print(msgid, line, node, args, confidence, col_offset)
         self.linter.add_message(msgid, line, node, args, confidence, col_offset)
 
     def check_consistency(self):
diff --git a/pylint/checkers/imports.py b/pylint/checkers/imports.py
index 0f926285..86c11129 100644
--- a/pylint/checkers/imports.py
+++ b/pylint/checkers/imports.py
@@ -789,8 +789,11 @@ class ImportsChecker(DeprecatedMixin, BaseChecker):
         try:
             return importnode.do_import_module(modname)
         except astroid.TooManyLevelsError:
+            print("Toomanylevelerrors", self._ignored_modules)
             if _ignore_import_failure(importnode, modname, self._ignored_modules):
+                print("Ignored !!")
                 return None
+            print("Adding message ?")
             self.add_message("relative-beyond-top-level", node=importnode)
         except astroid.AstroidSyntaxError as exc:
             message = "Cannot import {!r} due to syntax error {!r}".format(
diff --git a/tests/functional/i/import_aliasing.py b/tests/functional/i/import_aliasing.py
index dd75be4b..bc36302b 100644
--- a/tests/functional/i/import_aliasing.py
+++ b/tests/functional/i/import_aliasing.py
@@ -23,4 +23,4 @@ from . import foo as bar, foo2 as bar2
 from foo.bar import foobar as foobar  # [useless-import-alias]
 from foo.bar import foobar as foo
 from .foo.bar import f as foobar
-from ............a import b  # TODO there should be a relative-beyond-top-level here
+from ............a import b  # [relative-beyond-top-level]

Command used

python3 -m pytest . -k aliasing

Pylint output

Toomanylevelerrors ()
Adding message ?
relative-beyond-top-level None ImportFrom(modname='a',
           names=[('b', None)],
           level=12) None Confidence(name='UNDEFINED', description='Warning without any associated confidence level.') None


E       AssertionError: Wrong results for file "import_aliasing":
E       
E       Expected in testdata:
E         26: relative-beyond-top-level

Expected behavior

relative-beyond-top-level is raised.

Pylint version

pylint 2.10.0-dev0
astroid 2.6.7-dev0
Python 3.8.10 (default, Jun  2 2021, 10:49:15) 
[GCC 9.4.0]
@Pierre-Sassoulas Pierre-Sassoulas added Bug 🪲 False Negative 🦋 No message is emitted but something is wrong with the code labels Aug 15, 2021
@Pierre-Sassoulas
Copy link
Member Author

The warning was disabled in the functional test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🪲 False Negative 🦋 No message is emitted but something is wrong with the code
Projects
None yet
Development

No branches or pull requests

1 participant