OCA/pylint-odoo

ImportError: cannot import name 'NodeNG' from 'astroid'

Closed this issue · 1 comments

When i run
pylint --load-plugins=pylint_odoo -e odoolint my_app

it return error

File "/home/ubuntu/.local/lib/python3.8/site-packages/pylint_odoo/checkers/odoo_addons.py", line 108, in <module>
    from astroid import ClassDef, FunctionDef, NodeNG, nodes
ImportError: cannot import name 'NodeNG' from 'astroid' (/usr/lib/python3/dist-packages/astroid/__init__.py)

Module

pylint_odoo/checkers/odoo_addons.py

To Reproduce

Affected versions:9.0.5

Steps to reproduce the behavior:

  1. pip install pylint-odoo
  2. pylint --load-plugins=pylint_odoo -e odoolint my_app

Additional context
pylint 3.0.4
astroid 3.1.0
Python 3.8.10
pylint-odoo 9.0.5

@Nugjii

I have followed the same steps from virtualenv to use a clean env:

python3.8 -m virtualenv pylint_env
source pylint_env/bin/activate
python -m pip install pylint-odoo
python -m pylint --version
# pylint 3.0.4
# astroid 3.0.3
# Python 3.8.18 (default, Aug 24 2023, 19:48:18)
# [Clang 15.0.0 (clang-1500.1.0.2.5)]

Notice the version of astroid installed is different in your environment

python -m pylint --load-plugins=pylint_odoo -e odoolint ~/odoo/odoo/addons/lunch/models/lunch_order.py
# It ran without pylint exceptions

Forcing your same astroid version

python -m pip install astroid==3.1.0

Collecting astroid==3.1.0
  Downloading astroid-3.1.0-py3-none-any.whl.metadata (4.5 kB)
Requirement already satisfied: typing-extensions>=4.0.0 in ./pylint_env/lib/python3.8/site-packages (from astroid==3.1.0) (4.10.0)
Downloading astroid-3.1.0-py3-none-any.whl (275 kB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 275.6/275.6 kB 2.7 MB/s eta 0:00:00
Installing collected packages: astroid
  Attempting uninstall: astroid
    Found existing installation: astroid 3.0.3
    Uninstalling astroid-3.0.3:
      Successfully uninstalled astroid-3.0.3
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
pylint 3.0.4 requires astroid<=3.1.0-dev0,>=3.0.1, but you have astroid 3.1.0 which is incompatible.
Successfully installed astroid-3.1.0

Notice the ERROR dependency

And the error is reproduced running

python -m pylint --load-plugins=pylint_odoo -e odoolint ~/odoo/odoo/addons/lunch/models/lunch_order.py

Exception on node <ImportFrom l.4 at 0x10bbda8e0> in file '/Users/moylop260/odoo/odoo/addons/lunch/models/lunch_order.py'
Traceback (most recent call last):
  File "/private/tmp/pylint_env/lib/python3.8/site-packages/astroid/bases.py", line 243, in getattr
    values = self._proxied.instance_attr(name, context)
  File "/private/tmp/pylint_env/lib/python3.8/site-packages/astroid/nodes/scoped_nodes/scoped_nodes.py", line 2366, in instance_attr
    raise AttributeInferenceError(target=self, attribute=name, context=context)
astroid.exceptions.AttributeInferenceError: 'filtered' not found on <ClassDef.LunchOrder l.8 at 0x10bd23c40>.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/private/tmp/pylint_env/lib/python3.8/site-packages/astroid/bases.py", line 276, in igetattr
    get_attr = self.getattr(name, context, lookupclass=False)
  File "/private/tmp/pylint_env/lib/python3.8/site-packages/astroid/bases.py", line 253, in getattr
    raise AttributeInferenceError(
astroid.exceptions.AttributeInferenceError: 'filtered' not found on <Instance of .LunchOrder at 0x4491205504>.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/private/tmp/pylint_env/lib/python3.8/site-packages/astroid/nodes/scoped_nodes/scoped_nodes.py", line 2505, in igetattr
    attributes = self.getattr(name, context, class_context=class_context)
  File "/private/tmp/pylint_env/lib/python3.8/site-packages/astroid/nodes/scoped_nodes/scoped_nodes.py", line 2438, in getattr
    raise AttributeInferenceError(target=self, attribute=name, context=context)
astroid.exceptions.AttributeInferenceError: 'filtered' not found on <ClassDef.LunchOrder l.8 at 0x10bd23c40>.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/private/tmp/pylint_env/lib/python3.8/site-packages/pylint/checkers/variables.py", line 2068, in visit_importfrom
    module = node.do_import_module(name_parts[0])
  File "/private/tmp/pylint_env/lib/python3.8/site-packages/astroid/nodes/_base_nodes.py", line 168, in do_import_module
    return mymodule.import_module(
  File "/private/tmp/pylint_env/lib/python3.8/site-packages/astroid/nodes/scoped_nodes/scoped_nodes.py", line 463, in import_module
    return AstroidManager().ast_from_module_name(
  File "/private/tmp/pylint_env/lib/python3.8/site-packages/astroid/manager.py", line 266, in ast_from_module_name
    raise e
  File "/private/tmp/pylint_env/lib/python3.8/site-packages/astroid/manager.py", line 211, in ast_from_module_name
    found_spec = self.file_from_module_name(modname, context_file)
  File "/private/tmp/pylint_env/lib/python3.8/site-packages/astroid/manager.py", line 318, in file_from_module_name
    raise value.with_traceback(None)  # pylint: disable=no-member
astroid.exceptions.AstroidImportError: Failed to import module odoo with error:
No module named odoo.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/private/tmp/pylint_env/lib/python3.8/site-packages/pylint/utils/ast_walker.py", line 91, in walk
    callback(astroid)
  File "/private/tmp/pylint_env/lib/python3.8/site-packages/pylint/checkers/variables.py", line 2069, in visit_importfrom
    except astroid.AstroidBuildingException:
AttributeError: module 'astroid' has no attribute 'AstroidBuildingException'
/Users/moylop260/odoo/odoo/addons/lunch/models/lunch_order.py:1:0: F0002: /Users/moylop260/odoo/odoo/addons/lunch/models/lunch_order.py: Fatal error while checking '/Users/moylop260/odoo/odoo/addons/lunch/models/lunch_order.py'. Please open an issue in our bug tracker so we address this. There is a pre-filled template that you can use in '/Users/moylop260/Library/Caches/pylint/pylint-crash-2024-02-29-12-04-51.txt'. (astroid-error)

It is not a pylint-odoo error but package installation incompatibles

Try installing the correct one

pip install -U --force-reinstall astroid==3.0.3