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 on all conan recipe (pylint 2.14.0) #6908

Closed
ericLemanissier opened this issue Jun 10, 2022 · 8 comments
Closed

Crash on all conan recipe (pylint 2.14.0) #6908

ericLemanissier opened this issue Jun 10, 2022 · 8 comments
Labels
Crash 💥 A bug that makes pylint crash Downstream Bug 🪲 The problem happens in a lib depending on pylint, not pylint

Comments

@ericLemanissier
Copy link

ericLemanissier commented Jun 10, 2022

Bug description

When parsing the following file:

from conans import ConanFile

class LibGlvndConan(ConanFile):
    def build_requirements(self):
        self.build_requires("meson/0.62.2")

pylint crashed with a AstroidError and with the following stacktrace:

Traceback (most recent call last):
  File "/usr/local/python/lib/python3.10/site-packages/pylint/lint/pylinter.py", line 713, in _check_file
    check_astroid_module(ast_node)
  File "/usr/local/python/lib/python3.10/site-packages/pylint/lint/pylinter.py", line 912, in check_astroid_module
    retval = self._check_astroid_module(
  File "/usr/local/python/lib/python3.10/site-packages/pylint/lint/pylinter.py", line 962, in _check_astroid_module
    walker.walk(node)
  File "/usr/local/python/lib/python3.10/site-packages/pylint/utils/ast_walker.py", line 93, in walk
    self.walk(child)
  File "/usr/local/python/lib/python3.10/site-packages/pylint/utils/ast_walker.py", line 93, in walk
    self.walk(child)
  File "/usr/local/python/lib/python3.10/site-packages/pylint/utils/ast_walker.py", line 93, in walk
    self.walk(child)
  [Previous line repeated 2 more times]
  File "/usr/local/python/lib/python3.10/site-packages/pylint/utils/ast_walker.py", line 90, in walk
    callback(astroid)
  File "/usr/local/python/lib/python3.10/site-packages/pylint/checkers/typecheck.py", line 1114, in visit_attribute
    attr_parent = attr_node.parent
AttributeError: 'tuple' object has no attribute 'parent'

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

Traceback (most recent call last):
  File "/usr/local/python/lib/python3.10/site-packages/pylint/lint/pylinter.py", line 670, in _check_files
    self._check_file(get_ast, check_astroid_module, file)
  File "/usr/local/python/lib/python3.10/site-packages/pylint/lint/pylinter.py", line 715, in _check_file
    raise astroid.AstroidError from e
astroid.exceptions.AstroidError

.

Command used

pylint --output-format=json --enable=all --reports=no --disable=no-absolute-import --persistent=no --init-hook="import sys;sys.path.extend(['recipes/libglvnd/all',])" --load-plugins=conans.pylint_plugin recipes/libglvnd/all/conanfile.py

Pylint output

[
    {
        "type": "error",
        "module": "Command line",
        "obj": "",
        "line": 1,
        "column": 0,
        "endLine": null,
        "endColumn": null,
        "path": "Command line",
        "symbol": "bad-option-value",
        "message": "Bad option value for --disable. Don't recognize message no-absolute-import.",
        "message-id": "E0012"
    },
    {
        "type": "error",
        "module": "conanfile",
        "obj": "",
        "line": 1,
        "column": 0,
        "endLine": null,
        "endColumn": null,
        "path": "recipes/libglvnd/all/conanfile.py",
        "symbol": "conan1.x-deprecated-imports",
        "message": "Using deprecated imports from 'conans'. Check migration guide at https://docs.conan.io/en/latest/conan_v2.html",
        "message-id": "E9000"
    },
    {
        "type": "convention",
        "module": "conanfile",
        "obj": "",
        "line": 1,
        "column": 0,
        "endLine": null,
        "endColumn": null,
        "path": "recipes/libglvnd/all/conanfile.py",
        "symbol": "missing-module-docstring",
        "message": "Missing module docstring",
        "message-id": "C0114"
    },
    {
        "type": "convention",
        "module": "conanfile",
        "obj": "LibGlvndConan",
        "line": 3,
        "column": 0,
        "endLine": 3,
        "endColumn": 19,
        "path": "recipes/libglvnd/all/conanfile.py",
        "symbol": "missing-class-docstring",
        "message": "Missing class docstring",
        "message-id": "C0115"
    },
    {
        "type": "convention",
        "module": "conanfile",
        "obj": "LibGlvndConan.build_requirements",
        "line": 4,
        "column": 4,
        "endLine": 4,
        "endColumn": 26,
        "path": "recipes/libglvnd/all/conanfile.py",
        "symbol": "missing-function-docstring",
        "message": "Missing function or method docstring",
        "message-id": "C0116"
    },
    {
        "type": "fatal",
        "module": "conanfile",
        "obj": "",
        "line": 1,
        "column": 0,
        "endLine": null,
        "endColumn": null,
        "path": "recipes/libglvnd/all/conanfile.py",
        "symbol": "astroid-error",
        "message": "recipes/libglvnd/all/conanfile.py: Fatal error while checking 'recipes/libglvnd/all/conanfile.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/vscode/.cache/pylint/pylint-crash-2022-06-10-15.txt'.",
        "message-id": "F0002"
    }
]

Expected behavior

no error

Pylint version

pylint 2.14.1
astroid 2.11.5
Python 3.10.5 (main, Jun  9 2022, 13:59:07) [GCC 10.2.1 20210110]

OS / Environment

linux

Additional dependencies

bottle==0.12.21
certifi==2022.5.18.1
charset-normalizer==2.0.12
colorama==0.4.4
conan==1.49.0
distro==1.6.0
fasteners==0.17.3
idna==3.3
Jinja2==3.1.2
MarkupSafe==2.1.1
node-semver==0.6.1
patch-ng==1.17.4
pluginbase==1.0.1
Pygments==2.12.0
PyJWT==2.4.0
python-dateutil==2.8.2
PyYAML==6.0
requests==2.27.1
six==1.16.0
tqdm==4.64.0
urllib3==1.26.9

@ericLemanissier ericLemanissier added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Jun 10, 2022
@ericLemanissier
Copy link
Author

This error goes away either by removing --load-plugins=conans.pylint_plugin argument or downgrading pylint to 2.13.9

@Pierre-Sassoulas Pierre-Sassoulas added Crash 💥 A bug that makes pylint crash Downstream Bug 🪲 The problem happens in a lib depending on pylint, not pylint Needs investigation 🔬 A bug or crash where it's not immediately obvious what is happenning labels Jun 10, 2022
@DanielNoord
Copy link
Collaborator

I don't know the conans.pylint_plugin plugin, but seeing as that removes the issue I would report this against them. We don't control that plugin in this repository.

@ericLemanissier
Copy link
Author

ericLemanissier commented Jun 11, 2022

The plugin is quite simple and maintained in https://github.com/conan-io/conan/blob/develop/conans/pylint_plugin.py

Considering the same version of the plugin works with all versions of pylint before 2.14.0, you probably have a pointer to what could be the cause of the problem?

@DanielNoord
Copy link
Collaborator

It seems as if the attr_node is of an incorrect type. This is likely because of one of the transforms in the plugin: there is not tuple in the code you provided so I think the only way a tuple could be end up as attr_node is if the transform is doing so.

@ericLemanissier
Copy link
Author

ericLemanissier commented Jun 11, 2022

@DanielNoord
Copy link
Collaborator

Well, that bug was indeed caused by an incorrect transform, which was fixed in pylint-dev/astroid#1505.

It can't really be related to this issue, although a similar problem might occur on the plugin or in its interaction with other astroid plugins.

@Pierre-Sassoulas Pierre-Sassoulas removed the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Jun 12, 2022
@ericLemanissier
Copy link
Author

I am very sorry to ask for this, but I failed to find some examples. The plugin which triggers this crash basically does this:

def transform_conanfile(node):
    node.locals["build_requires"] = [MANAGER.ast_from_module_name("conans.client.graph.graph_manager").lookup("_RecipeBuildRequires")]


MANAGER.register_transform(
    astroid.ClassDef, transform_conanfile,
    lambda node: node.qname() == "conans.model.conan_file.ConanFile")

The intent is to declare a dynamic field named build_requires of type conans.client.graph.graph_manager._RecipeBuildRequires in conans.model.conan_file.ConanFile class. Do you see something obviously wrong ?

@DanielNoord
Copy link
Collaborator

@ericLemanissier The following fixes the crash:

diff --git a/conans/pylint_plugin.py b/conans/pylint_plugin.py
index 892a51850..4e87c2855 100644
--- a/conans/pylint_plugin.py
+++ b/conans/pylint_plugin.py
@@ -39,7 +39,7 @@ def transform_conanfile(node):
     }
 
     for f, t in dynamic_fields.items():
-        node.locals[f] = [t]
+        node.locals[f] = [i for i in t]
 
 
 MANAGER.register_transform(

I'm not sure if this will work for all transforms but in the case of build_requires t is a tuple. Since the value for locals should be a list it shouldn't be list(tuple()) but list(i for i in tuple()). It is a similar issue as with pylint-dev/astroid#1505 but only fixable with your pylint plugin as that's where the issue originates from.

I'm going to close this as downstream issue. If you need any help applying the patch to the conan repo feel free to ping me there!

@DanielNoord DanielNoord closed this as not planned Won't fix, can't repro, duplicate, stale Jun 13, 2022
@DanielNoord DanielNoord removed the Needs investigation 🔬 A bug or crash where it's not immediately obvious what is happenning label Jun 13, 2022
memsharded pushed a commit to conan-io/conan that referenced this issue Jun 13, 2022
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 Downstream Bug 🪲 The problem happens in a lib depending on pylint, not pylint
Projects
None yet
Development

No branches or pull requests

3 participants