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

AttributeInferenceError with click and pylint 2.9 #4692

Closed
vonschultz opened this issue Jul 8, 2021 · 0 comments · Fixed by #4700 or pylint-dev/astroid#1110
Closed

AttributeInferenceError with click and pylint 2.9 #4692

vonschultz opened this issue Jul 8, 2021 · 0 comments · Fixed by #4700 or pylint-dev/astroid#1110
Assignees
Labels
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 Regression
Milestone

Comments

@vonschultz
Copy link

Steps to reproduce

#!/bin/bash
python3.8 -m venv venv
source venv/bin/activate
pip install click==8.0.1 pylint==2.9.3
cat > test.py <<EOF
import click


for name, item in click.__dict__.items():
    _ = isinstance(item, click.Command) and item != 'foo'

EOF
pylint test.py

Current behavior

Collecting click==8.0.1
  Using cached click-8.0.1-py3-none-any.whl (97 kB)
Collecting pylint==2.9.3
  Using cached pylint-2.9.3-py3-none-any.whl (372 kB)
Collecting astroid<2.7,>=2.6.2
  Using cached astroid-2.6.2-py3-none-any.whl (228 kB)
Collecting mccabe<0.7,>=0.6
  Using cached mccabe-0.6.1-py2.py3-none-any.whl (8.6 kB)
Collecting isort<6,>=4.2.5
  Using cached isort-5.9.2-py3-none-any.whl (105 kB)
Collecting toml>=0.7.1
  Using cached toml-0.10.2-py2.py3-none-any.whl (16 kB)
Processing /home/von/.cache/pip/wheels/5f/fd/9e/b6cf5890494cb8ef0b5eaff72e5d55a70fb56316007d6dfe73/wrapt-1.12.1-cp38-cp38-linux_x86_64.whl
Collecting lazy-object-proxy>=1.4.0
  Using cached lazy_object_proxy-1.6.0-cp38-cp38-manylinux1_x86_64.whl (58 kB)
Installing collected packages: click, wrapt, lazy-object-proxy, astroid, mccabe, isort, toml, pylint
Successfully installed astroid-2.6.2 click-8.0.1 isort-5.9.2 lazy-object-proxy-1.6.0 mccabe-0.6.1 pylint-2.9.3 toml-0.10.2 wrapt-1.12.1
************* Module test
test.py:6:0: C0305: Trailing newlines (trailing-newlines)
test.py:1:0: C0114: Missing module docstring (missing-module-docstring)
Exception on node <AssignName._ l.5 at 0x7fbf375d0ee0> in file '/tmp/test.py'
Traceback (most recent call last):
  File "/tmp/venv/lib/python3.8/site-packages/astroid/inference_tip.py", line 19, in _inference_tip_cached
    return iter(_cache[func, node])
KeyError: (<function register_builtin_transform.<locals>._transform_wrapper at 0x7fbf379eb310>, <Call l.5 at 0x7fbf37570070>)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/tmp/venv/bin/pylint", line 8, in <module>
    sys.exit(run_pylint())
  File "/tmp/venv/lib/python3.8/site-packages/pylint/__init__.py", line 24, in run_pylint
    PylintRun(sys.argv[1:])
  File "/tmp/venv/lib/python3.8/site-packages/pylint/lint/run.py", line 384, in __init__
    linter.check(args)
  File "/tmp/venv/lib/python3.8/site-packages/pylint/lint/pylinter.py", line 973, in check
    self._check_files(
  File "/tmp/venv/lib/python3.8/site-packages/pylint/lint/pylinter.py", line 1007, in _check_files
    self._check_file(get_ast, check_astroid_module, name, filepath, modname)
  File "/tmp/venv/lib/python3.8/site-packages/pylint/lint/pylinter.py", line 1033, in _check_file
    check_astroid_module(ast_node)
  File "/tmp/venv/lib/python3.8/site-packages/pylint/lint/pylinter.py", line 1170, in check_astroid_module
    retval = self._check_astroid_module(
  File "/tmp/venv/lib/python3.8/site-packages/pylint/lint/pylinter.py", line 1215, in _check_astroid_module
    walker.walk(ast_node)
  File "/tmp/venv/lib/python3.8/site-packages/pylint/utils/ast_walker.py", line 77, in walk
    self.walk(child)
  File "/tmp/venv/lib/python3.8/site-packages/pylint/utils/ast_walker.py", line 77, in walk
    self.walk(child)
  File "/tmp/venv/lib/python3.8/site-packages/pylint/utils/ast_walker.py", line 77, in walk
    self.walk(child)
  File "/tmp/venv/lib/python3.8/site-packages/pylint/utils/ast_walker.py", line 74, in walk
    callback(astroid)
  File "/tmp/venv/lib/python3.8/site-packages/pylint/checkers/base.py", line 1982, in visit_assignname
    if isinstance(utils.safe_infer(assign_type.value), astroid.ClassDef):
  File "/tmp/venv/lib/python3.8/site-packages/pylint/checkers/utils.py", line 1177, in safe_infer
    value = next(infer_gen)
  File "/tmp/venv/lib/python3.8/site-packages/astroid/node_classes.py", line 353, in infer
    yield from self._infer(context, **kwargs)
  File "/tmp/venv/lib/python3.8/site-packages/astroid/decorators.py", line 136, in raise_if_nothing_inferred
    yield next(generator)
  File "/tmp/venv/lib/python3.8/site-packages/astroid/decorators.py", line 100, in wrapped
    res = next(generator)
  File "/tmp/venv/lib/python3.8/site-packages/astroid/inference.py", line 447, in _infer_boolop
    for pair in itertools.product(*values):
  File "/tmp/venv/lib/python3.8/site-packages/astroid/node_classes.py", line 343, in infer
    results = tuple(self._explicit_inference(self, context, **kwargs))
  File "/tmp/venv/lib/python3.8/site-packages/astroid/inference_tip.py", line 21, in _inference_tip_cached
    result = func(*args, **kwargs)
  File "/tmp/venv/lib/python3.8/site-packages/astroid/brain/brain_builtin_inference.py", line 193, in _transform_wrapper
    result = transform(node, context=context)
  File "/tmp/venv/lib/python3.8/site-packages/astroid/brain/brain_builtin_inference.py", line 738, in infer_isinstance
    isinstance_bool = helpers.object_isinstance(obj_node, class_container, context)
  File "/tmp/venv/lib/python3.8/site-packages/astroid/helpers.py", line 128, in object_isinstance
    obj_type = object_type(node, context)
  File "/tmp/venv/lib/python3.8/site-packages/astroid/helpers.py", line 84, in object_type
    types = set(_object_type(node, context))
  File "/tmp/venv/lib/python3.8/site-packages/astroid/helpers.py", line 57, in _object_type
    for inferred in node.infer(context=context):
  File "/tmp/venv/lib/python3.8/site-packages/astroid/node_classes.py", line 367, in infer
    for i, result in enumerate(generator):
  File "/tmp/venv/lib/python3.8/site-packages/astroid/decorators.py", line 146, in raise_if_nothing_inferred
    yield from generator
  File "/tmp/venv/lib/python3.8/site-packages/astroid/decorators.py", line 100, in wrapped
    res = next(generator)
  File "/tmp/venv/lib/python3.8/site-packages/astroid/bases.py", line 144, in _infer_stmts
    for inferred in stmt.infer(context=context):
  File "/tmp/venv/lib/python3.8/site-packages/astroid/node_classes.py", line 367, in infer
    for i, result in enumerate(generator):
  File "/tmp/venv/lib/python3.8/site-packages/astroid/decorators.py", line 146, in raise_if_nothing_inferred
    yield from generator
  File "/tmp/venv/lib/python3.8/site-packages/astroid/decorators.py", line 100, in wrapped
    res = next(generator)
  File "/tmp/venv/lib/python3.8/site-packages/astroid/bases.py", line 144, in _infer_stmts
    for inferred in stmt.infer(context=context):
  File "/tmp/venv/lib/python3.8/site-packages/astroid/node_classes.py", line 367, in infer
    for i, result in enumerate(generator):
  File "/tmp/venv/lib/python3.8/site-packages/astroid/decorators.py", line 136, in raise_if_nothing_inferred
    yield next(generator)
  File "/tmp/venv/lib/python3.8/site-packages/astroid/decorators.py", line 97, in wrapped
    generator = _func(node, context, **kwargs)
  File "/tmp/venv/lib/python3.8/site-packages/astroid/inference.py", line 276, in infer_import_from
    name = self.real_name(name)
  File "/tmp/venv/lib/python3.8/site-packages/astroid/mixins.py", line 115, in real_name
    raise AttributeInferenceError(
astroid.exceptions.AttributeInferenceError: Could not find original name for items in <ImportFrom l.7 at 0x7fbf37570520>

We also get exceptions on 2.9.0, as well as when we do pip install pylint astroid --pre -U

Expected behavior

Collecting click==8.0.1
  Using cached click-8.0.1-py3-none-any.whl (97 kB)
Collecting pylint==2.8.3
  Using cached pylint-2.8.3-py3-none-any.whl (357 kB)
Collecting toml>=0.7.1
  Using cached toml-0.10.2-py2.py3-none-any.whl (16 kB)
Collecting isort<6,>=4.2.5
  Using cached isort-5.9.2-py3-none-any.whl (105 kB)
Collecting mccabe<0.7,>=0.6
  Using cached mccabe-0.6.1-py2.py3-none-any.whl (8.6 kB)
Collecting astroid==2.5.6
  Using cached astroid-2.5.6-py3-none-any.whl (219 kB)
Processing /home/von/.cache/pip/wheels/5f/fd/9e/b6cf5890494cb8ef0b5eaff72e5d55a70fb56316007d6dfe73/wrapt-1.12.1-cp38-cp38-linux_x86_64.whl
Collecting lazy-object-proxy>=1.4.0
  Using cached lazy_object_proxy-1.6.0-cp38-cp38-manylinux1_x86_64.whl (58 kB)
Installing collected packages: click, toml, isort, mccabe, wrapt, lazy-object-proxy, astroid, pylint
Successfully installed astroid-2.5.6 click-8.0.1 isort-5.9.2 lazy-object-proxy-1.6.0 mccabe-0.6.1 pylint-2.8.3 toml-0.10.2 wrapt-1.12.1
************* Module test
test.py:6:0: C0305: Trailing newlines (trailing-newlines)
test.py:1:0: C0114: Missing module docstring (missing-module-docstring)

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

(Or similar; this is how it looks with Pylint 2.8.3. Note that we don't get any exceptions.)

pylint --version output

Result of pylint --version output:

pylint 2.9.3
astroid 2.6.2
Python 3.8.10 (default, Jun  2 2021, 10:49:15) 
[GCC 9.4.0]
@Pierre-Sassoulas Pierre-Sassoulas added Crash 💥 A bug that makes pylint crash Regression labels Jul 8, 2021
@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.9.4 milestone Jul 8, 2021
@Pierre-Sassoulas Pierre-Sassoulas added the Blocker 🙅 Blocks the next release label Jul 8, 2021
Pierre-Sassoulas added a commit to pylint-dev/astroid that referenced this issue Jul 10, 2021
@Pierre-Sassoulas Pierre-Sassoulas added the Needs astroid update Needs an astroid update (probably a release too) before being mergable label Jul 10, 2021
Pierre-Sassoulas added a commit to Pierre-Sassoulas/pylint that referenced this issue Jul 10, 2021
@Pierre-Sassoulas Pierre-Sassoulas modified the milestones: 2.9.4, 2.9.5 Jul 11, 2021
@Pierre-Sassoulas Pierre-Sassoulas self-assigned this Jul 20, 2021
Pierre-Sassoulas added a commit to Pierre-Sassoulas/pylint that referenced this issue Jul 21, 2021
Pierre-Sassoulas added a commit to Pierre-Sassoulas/pylint that referenced this issue Jul 21, 2021
Pierre-Sassoulas added a commit to Pierre-Sassoulas/pylint that referenced this issue Jul 21, 2021
Pierre-Sassoulas added a commit to Pierre-Sassoulas/pylint that referenced this issue Jul 21, 2021
Pierre-Sassoulas added a commit to Pierre-Sassoulas/pylint that referenced this issue Jul 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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 Regression
Projects
None yet
2 participants