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

Crash with relative import in from statement #4775

Closed
rublag opened this issue Jul 30, 2021 · 1 comment · Fixed by #4848
Closed

Crash with relative import in from statement #4775

rublag opened this issue Jul 30, 2021 · 1 comment · Fixed by #4848
Assignees
Labels
Blocker 🙅 Blocks the next release Bug 🪲 Crash 💥 A bug that makes pylint crash
Milestone

Comments

@rublag
Copy link

rublag commented Jul 30, 2021

Bug description

File test.py

# pylint: disable=missing-module-docstring
from .a import b

It seems like this commit introduced the bug:
0f8212f#diff-7d982c7ee8d920542a08ef8e7a73fddf8929599d2c13507a7b3b6bf2a4371b6fR112

Command used

pylint test.py

Pylint output

Exception on node <ImportFrom l.2 at 0x7f1be7effbb0> in file '/tmp/plt/test.py'
Traceback (most recent call last):
  File "/home/rublag/projects/ecom/server/.venv/bin/pylint", line 8, in <module>
    sys.exit(run_pylint())
  File "/home/rublag/projects/ecom/server/.venv/lib/python3.9/site-packages/pylint/__init__.py", line 24, in run_pylint
    PylintRun(sys.argv[1:])
  File "/home/rublag/projects/ecom/server/.venv/lib/python3.9/site-packages/pylint/lint/run.py", line 384, in __init__
    linter.check(args)
  File "/home/rublag/projects/ecom/server/.venv/lib/python3.9/site-packages/pylint/lint/pylinter.py", line 975, in check
    self._check_files(
  File "/home/rublag/projects/ecom/server/.venv/lib/python3.9/site-packages/pylint/lint/pylinter.py", line 1009, in _check_files
    self._check_file(get_ast, check_astroid_module, name, filepath, modname)
  File "/home/rublag/projects/ecom/server/.venv/lib/python3.9/site-packages/pylint/lint/pylinter.py", line 1035, in _check_file
    check_astroid_module(ast_node)
  File "/home/rublag/projects/ecom/server/.venv/lib/python3.9/site-packages/pylint/lint/pylinter.py", line 1172, in check_astroid_module
    retval = self._check_astroid_module(
  File "/home/rublag/projects/ecom/server/.venv/lib/python3.9/site-packages/pylint/lint/pylinter.py", line 1217, in _check_astroid_module
    walker.walk(ast_node)
  File "/home/rublag/projects/ecom/server/.venv/lib/python3.9/site-packages/pylint/utils/ast_walker.py", line 77, in walk
    self.walk(child)
  File "/home/rublag/projects/ecom/server/.venv/lib/python3.9/site-packages/pylint/utils/ast_walker.py", line 74, in walk
    callback(astroid)
  File "/home/rublag/projects/ecom/server/.venv/lib/python3.9/site-packages/pylint/checkers/deprecated.py", line 112, in visit_importfrom
    basename = get_import_name(node, basename)
  File "/home/rublag/projects/ecom/server/.venv/lib/python3.9/site-packages/pylint/checkers/utils.py", line 1552, in get_import_name
    modname = root.relative_to_absolute_name(
  File "/home/rublag/projects/ecom/server/.venv/lib/python3.9/site-packages/astroid/scoped_nodes.py", line 725, in relative_to_absolute_name
    raise TooManyLevelsError(level=level, name=self.name)
astroid.exceptions.TooManyLevelsError: Relative import with too many levels (1) for module 'test'

Expected behavior

No crash

Pylint version

pylint 2.9.5
astroid 2.6.5
Python 3.9.6 (default, Jun 30 2021, 10:22:16) 
[GCC 11.1.0]
@rublag rublag added Bug 🪲 Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Jul 30, 2021
@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.10.0 milestone Jul 30, 2021
@Pierre-Sassoulas Pierre-Sassoulas added Blocker 🙅 Blocks the next release Crash 💥 A bug that makes pylint crash Needs astroid update Needs an astroid update (probably a release too) before being mergable and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Jul 30, 2021
@yangkenneth
Copy link

Running into the same issue, last working version was 2.9.3 on my end.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Blocker 🙅 Blocks the next release Bug 🪲 Crash 💥 A bug that makes pylint crash
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants