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

regression: modified_iterating_checker exception #7528

Closed
belm0 opened this issue Sep 26, 2022 · 6 comments · Fixed by #7541
Closed

regression: modified_iterating_checker exception #7528

belm0 opened this issue Sep 26, 2022 · 6 comments · Fixed by #7541
Labels
Crash 💥 A bug that makes pylint crash Needs PR This issue is accepted, sufficiently specified and now needs an implementation
Milestone

Comments

@belm0
Copy link
Contributor

belm0 commented Sep 26, 2022

Bug description

modified_iterating_checker exception on code that passes fine with earlier pylint versions

from enum import Enum

class MyEnum(Enum):
    FOO = 1
    BAR = 2

class MyClass:
    ENUM_SET = {MyEnum.FOO, MyEnum.BAR}

    def useless(self):
        other_set = set(self.ENUM_SET)
        for item in self.ENUM_SET:
            other_set.remove(item)

Configuration

No response

Command used

pylint

Pylint output

pylint crashed with a ``AstroidError`` and with the following stacktrace:

Traceback (most recent call last):
  File "/.../lib/python3.8/site-pac
kages/pylint/lint/pylinter.py", line 782, in _lint_file
    check_astroid_module(module)
  File "/.../lib/python3.8/site-pac
kages/pylint/lint/pylinter.py", line 1049, in check_astroid_module
    retval = self._check_astroid_module(
  File "/.../lib/python3.8/site-pac
kages/pylint/lint/pylinter.py", line 1099, in _check_astroid_module
    walker.walk(node)
  File "/.../lib/python3.8/site-pac
kages/pylint/utils/ast_walker.py", line 93, in walk
    self.walk(child)
  File "/.../lib/python3.8/site-pac
kages/pylint/utils/ast_walker.py", line 93, in walk
    self.walk(child)
  File "/.../lib/python3.8/site-packages/pylint/utils/ast_walker.py", line 93, in walk
    self.walk(child)
  File "/.../lib/python3.8/site-packages/pylint/utils/ast_walker.py", line 90, in walk
    callback(astroid)
  File "/.../lib/python3.8/site-packages/pylint/checkers/modified_iterating_checker.py", line 60, in visit_for
    self._modified_iterating_check_on_node_and_children(body_node, iter_obj)
  File "/.../lib/python3.8/site-packages/pylint/checkers/modified_iterating_checker.py", line 68, in _modified_iterating_check_on_node_and_children
    self._modified_iterating_check_on_node_and_children(child, iter_obj)
  File "/.../lib/python3.8/site-packages/pylint/checkers/modified_iterating_checker.py", line 66, in _modified_iterating_check_on_node_and_children
    self._modified_iterating_check(body_node, iter_obj)
  File "/.../lib/python3.8/site-packages/pylint/checkers/modified_iterating_checker.py", line 90, in _modified_iterating_check
    elif self._modified_iterating_set_cond(node, iter_obj):
  File "/.../lib/python3.8/site-packages/pylint/checkers/modified_iterating_checker.py", line 177, in _modified_iterating_set_cond
    self._common_cond_list_set(node, iter_obj, infer_val)
  File "/.../lib/python3.8/site-packages/pylint/checkers/modified_iterating_checker.py", line 120, in _common_cond_list_set
    node.value.func.expr.name == iter_obj.name
AttributeError: 'Attribute' object has no attribute 'name'

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

Traceback (most recent call last):
  File "/.../lib/python3.8/site-packages/pylint/lint/pylinter.py", line 747, in _lint_files
    self._lint_file(fileitem, module, check_astroid_module)
  File "/.../lib/python3.8/site-packages/pylint/lint/pylinter.py", line 784, in _lint_file
    raise astroid.AstroidError from e
astroid.exceptions.AstroidError

Expected behavior

no error

Pylint version

pylint 2.15.3
astroid 2.12.10
Python 3.8.12 (default, Sep 23 2021, 08:42:37)
[Clang 12.0.0 (clang-1200.0.32.29)]

OS / Environment

No response

Additional dependencies

No response

@belm0 belm0 added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Sep 26, 2022
@Pierre-Sassoulas Pierre-Sassoulas added Needs reproduction 🔍 Need a way to reproduce it locally on a maintainer's machine Crash 💥 A bug that makes pylint crash and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Sep 26, 2022
@belm0
Copy link
Contributor Author

belm0 commented Sep 26, 2022

@Pierre-Sassoulas I'd updated the original report with a reproduction, please take another look.

@Pierre-Sassoulas Pierre-Sassoulas added Needs PR This issue is accepted, sufficiently specified and now needs an implementation and removed Needs reproduction 🔍 Need a way to reproduce it locally on a maintainer's machine labels Sep 26, 2022
@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.15.4 milestone Sep 26, 2022
@Pierre-Sassoulas
Copy link
Member

Thank you for opening the issue and the reproducer, this fail on main.

@DanielNoord
Copy link
Collaborator

@orSolocate Do you want to take a look at this?

@clavedeluna
Copy link
Collaborator

clavedeluna commented Sep 29, 2022

Tested in the following versions of pylint

2.13.0 (can repro same error as issue)
2.14.0 (can't repro)
2.15.0 (can't repro)
2.15.2, 2.15.3 (can repro same error as issue)

So issue was there in the original implementation of the modified iterating checker, fixed in a couple minor versions, then came back up again. If I have more time today I can continue to look into this with git bisect and find the commit.

@clavedeluna
Copy link
Collaborator

Git bisect suggests this commit brought the issue back in pylint v2.15.2

I can continue with the fix later today.

@orSolocate
Copy link
Contributor

@clavedeluna thanks for the fix man!

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 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.

5 participants