Closed
Description
Bug description
Let's say you have the following directory structure:
$ tree package
package
├── celery.py
└── __init__.py
and celery.py
has a content import celery.result
.
You can generate the above result using:
mkdir package
touch package/__init__.py
echo "import celery.result" > package/celery.py
This crashes pylint. See below for the traceback. Note that astroid==2.12.9
works, it's probably a regression in 2.12.10
Configuration
No response
Command used
`pylint package`
Pylint output
Content:
When parsing the following file:import celery.resultpylint crashed with a
AstroidError
and with the following stacktrace:Traceback (most recent call last): File "/home/saugat/projects/iterative/dvc/venv/lib/python3.11/site-packages/pylint/lint/pylinter.py", line 782, in _lint_file check_astroid_module(module) File "/home/saugat/projects/iterative/dvc/venv/lib/python3.11/site-packages/pylint/lint/pylinter.py", line 1049, in check_astroid_module retval = self._check_astroid_module( ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/saugat/projects/iterative/dvc/venv/lib/python3.11/site-packages/pylint/lint/pylinter.py", line 1099, in _check_astroid_module walker.walk(node) File "/home/saugat/projects/iterative/dvc/venv/lib/python3.11/site-packages/pylint/utils/ast_walker.py", line 93, in walk self.walk(child) File "/home/saugat/projects/iterative/dvc/venv/lib/python3.11/site-packages/pylint/utils/ast_walker.py", line 90, in walk callback(astroid) File "/home/saugat/projects/iterative/dvc/venv/lib/python3.11/site-packages/pylint/checkers/imports.py", line 497, in visit_import self._add_imported_module(node, imported_module.name) File "/home/saugat/projects/iterative/dvc/venv/lib/python3.11/site-packages/pylint/checkers/imports.py", line 833, in _add_imported_module importedmodname = astroid.modutils.get_module_part( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/saugat/projects/iterative/dvc/venv/lib/python3.11/site-packages/astroid/modutils.py", line 438, in get_module_part file_from_modpath( File "/home/saugat/projects/iterative/dvc/venv/lib/python3.11/site-packages/astroid/modutils.py", line 334, in file_from_modpath return file_info_from_modpath(modpath, path, context_file).location ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/saugat/projects/iterative/dvc/venv/lib/python3.11/site-packages/astroid/modutils.py", line 384, in file_info_from_modpath return _spec_from_modpath(modpath, path, context) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/saugat/projects/iterative/dvc/venv/lib/python3.11/site-packages/astroid/modutils.py", line 590, in _spec_from_modpath found_spec = spec.find_spec(modpath, [context]) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/saugat/projects/iterative/dvc/venv/lib/python3.11/site-packages/astroid/interpreter/_import/spec.py", line 392, in find_spec finder, spec = _find_spec_with_path( ^^^^^^^^^^^^^^^^^^^^^ File "/home/saugat/projects/iterative/dvc/venv/lib/python3.11/site-packages/astroid/interpreter/_import/spec.py", line 354, in _find_spec_with_path spec = finder_instance.find_module( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/saugat/projects/iterative/dvc/venv/lib/python3.11/site-packages/astroid/interpreter/_import/spec.py", line 204, in find_module submodule_path = sys.modules[modname].__path__ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: module 'celery.result' has no attribute '__path__' The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/home/saugat/projects/iterative/dvc/venv/lib/python3.11/site-packages/pylint/lint/pylinter.py", line 747, in _lint_files self._lint_file(fileitem, module, check_astroid_module) File "/home/saugat/projects/iterative/dvc/venv/lib/python3.11/site-packages/pylint/lint/pylinter.py", line 784, in _lint_file raise astroid.AstroidError from e astroid.exceptions.AstroidError
Expected behavior
Pylint does not crashes.
Pylint version
pylint 2.15.2
astroid 2.12.10
Python 3.11.0rc1+ (heads/3.11:2ba877258a, Aug 29 2022, 17:05:58) [GCC 12.2.0]
OS / Environment
No response
Additional dependencies
No response