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

'from . import *' causes an IndexError #8749

Closed
xiaxinmeng opened this issue Jun 7, 2023 · 4 comments · Fixed by pylint-dev/astroid#2202
Closed

'from . import *' causes an IndexError #8749

xiaxinmeng opened this issue Jun 7, 2023 · 4 comments · Fixed by pylint-dev/astroid#2202
Labels
Crash 💥 A bug that makes pylint crash Needs astroid update Needs an astroid update (probably a release too) before being mergable Needs PR This issue is accepted, sufficiently specified and now needs an implementation
Milestone

Comments

@xiaxinmeng
Copy link

'from . import *' triggers an IndexError of pylint.

pylint_example.py:

print('hi')
from . import *

The expected output

No fatal error

The actual output:

************* Module pylint_example
Desktop/pylint_example.py:14:7: C0303: Trailing whitespace (trailing-whitespace)
Desktop/pylint_example.py:17:17: C0303: Trailing whitespace (trailing-whitespace)
Desktop/pylint_example.py:61:0: C0305: Trailing newlines (trailing-newlines)
Desktop/pylint_example.py:1:0: C0114: Missing module docstring (missing-module-docstring)
Desktop/pylint_example.py:1:0: W0401: Wildcard import  (wildcard-import)
Exception on node <ImportFrom l.1 at 0x7f8021eb4b10> in file '/home/xxm/Desktop/pylint_example.py'
Traceback (most recent call last):
  File "/home/xxm/.local/lib/python3.11/site-packages/pylint/utils/ast_walker.py", line 91, in walk
    callback(astroid)
  File "/home/xxm/.local/lib/python3.11/site-packages/pylint/checkers/imports.py", line 556, in visit_importfrom
    self._add_imported_module(node, imported_module.name)
  File "/home/xxm/.local/lib/python3.11/site-packages/pylint/checkers/imports.py", line 877, in _add_imported_module
    importedmodname = astroid.modutils.get_module_part(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/xxm/.local/lib/python3.11/site-packages/astroid/modutils.py", line 433, in get_module_part
    while parts[starti] == "":  # for all further dots: change context
          ~~~~~^^^^^^^^
IndexError: list index out of range
Desktop/pylint_example.py:1:0: F0002: /home/xxm/Desktop/pylint_example.py: Fatal error while checking '/home/xxm/Desktop/pylint_example.py'. Please open an issue in our bug tracker so we address this. There is a pre-filled template that you can use in '/home/xxm/.cache/pylint/pylint-crash-2023-06-07-13-42-57.txt'. (astroid-error)

------------------------------------------------------------------
Your code has been rated at 0.00/10 (previous run: 0.00/10, +0.00)

Test Environment:
pylint 3.0.0b1
astroid 3.0.0a5-dev0
Python 3.11.3
Ubuntu 18.04

@Pierre-Sassoulas Pierre-Sassoulas added Crash 💥 A bug that makes pylint crash Needs PR This issue is accepted, sufficiently specified and now needs an implementation labels Jun 7, 2023
@Pierre-Sassoulas
Copy link
Member

Pierre-Sassoulas commented Jun 7, 2023

You're doing so much work there @xiaxinmeng, we never had so much crashes discovered at once by a single contributor. If you don't mind how are you finding all of those ? Ideally we'd like to be able to catch them ourselves before releasing :)

@jacobtylerwalls jacobtylerwalls added the Needs astroid update Needs an astroid update (probably a release too) before being mergable label Jun 7, 2023
@jacobtylerwalls jacobtylerwalls self-assigned this Jun 7, 2023
@jacobtylerwalls jacobtylerwalls added this to the 2.17.6 milestone Jun 7, 2023
@jacobtylerwalls jacobtylerwalls modified the milestones: 2.17.6, 2.17.5 Jun 7, 2023
@xiaxinmeng
Copy link
Author

Thanks, our team is currently developing a new fuzzer specifically designed to test static analysis tools like pylint and mypy. Although the tool is not yet fully complete, we are actively working on it. Once we are ready, we will open-source the tool on GitHub. We hope that these reported bugs will be helpful for the maintenance and improvement of pylint. Thanks again.

@Pierre-Sassoulas
Copy link
Member

Great to hear ! It's already providing a tremendous amount of value imo ;) Did you consider testing it on autoformatter's result also (like black) ?

@xiaxinmeng
Copy link
Author

This is a great suggestion. Currently, we have developed a simple prototype of the tool. I believe it would not be difficult to integrate it with an autoformatter's result by making a few modifications. Thank you for the suggestion! Currently, we are in the process of expanding the functionality of this tool. One of the key areas we are focusing on is the detection of behavior bugs, i.e, bugs that lead to unexpected behaviors. By enhancing the tool, we aim to provide more comprehensive bug detection capabilities.

@jacobtylerwalls jacobtylerwalls removed their assignment Jun 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Crash 💥 A bug that makes pylint crash Needs astroid update Needs an astroid update (probably a release too) before being mergable Needs PR This issue is accepted, sufficiently specified and now needs an implementation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants