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 'Attribute' object has no attribute 'name' #6557

Closed
FPENGKAR opened this issue May 9, 2022 · 3 comments · Fixed by #6579
Closed

Crash 'Attribute' object has no attribute 'name' #6557

FPENGKAR opened this issue May 9, 2022 · 3 comments · Fixed by #6579
Assignees
Labels
Crash 💥 A bug that makes pylint crash
Milestone

Comments

@FPENGKAR
Copy link

FPENGKAR commented May 9, 2022

Bug description

class A:
  pass

my_dict = {}
a = A()
for input_output in my_dict.items():
  a.input_output = input_output
  my_dict[a.input_output[0]]

Configuration

No response

Command used

pylint with a settings file

Pylint output

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

Traceback (most recent call last):
  File "/home/azureuser/runners/ScenarioExtractor_runner/_work/_tool/Python/3.10.1/x64/lib/python3.10/site-packages/pylint/lint/pylinter.py", line 1034, in _check_files
    self._check_file(get_ast, check_astroid_module, file)
  File "/home/azureuser/runners/ScenarioExtractor_runner/_work/_tool/Python/3.10.1/x64/lib/python3.10/site-packages/pylint/lint/pylinter.py", line 1069, in _check_file
    check_astroid_module(ast_node)
  File "/home/azureuser/runners/ScenarioExtractor_runner/_work/_tool/Python/3.10.1/x64/lib/python3.10/site-packages/pylint/lint/pylinter.py", line 1203, in check_astroid_module
    retval = self._check_astroid_module(
  File "/home/azureuser/runners/ScenarioExtractor_runner/_work/_tool/Python/3.10.1/x64/lib/python3.10/site-packages/pylint/lint/pylinter.py", line 1250, in _check_astroid_module
    walker.walk(node)
  File "/home/azureuser/runners/ScenarioExtractor_runner/_work/_tool/Python/3.10.1/x64/lib/python3.10/site-packages/pylint/utils/ast_walker.py", line 75, in walk
    self.walk(child)
  File "/home/azureuser/runners/ScenarioExtractor_runner/_work/_tool/Python/3.10.1/x64/lib/python3.10/site-packages/pylint/utils/ast_walker.py", line 75, in walk
    self.walk(child)
  File "/home/azureuser/runners/ScenarioExtractor_runner/_work/_tool/Python/3.10.1/x64/lib/python3.10/site-packages/pylint/utils/ast_walker.py", line 75, in walk
    self.walk(child)
  [Previous line repeated 1 more time]
  File "/home/azureuser/runners/ScenarioExtractor_runner/_work/_tool/Python/3.10.1/x64/lib/python3.10/site-packages/pylint/utils/ast_walker.py", line 72, in walk
    callback(astroid)
  File "/home/azureuser/runners/ScenarioExtractor_runner/_work/_tool/Python/3.10.1/x64/lib/python3.10/site-packages/pylint/checkers/refactoring/refactoring_checker.py", line 637, in visit_for
    self._check_unnecessary_dict_index_lookup(node)
  File "/home/azureuser/runners/ScenarioExtractor_runner/_work/_tool/Python/3.10.1/x64/lib/python3.10/site-packages/pylint/checkers/refactoring/refactoring_checker.py", line 1906, in _check_unneces
sary_dict_index_lookup
    or node.target.name != value.value.name
AttributeError: 'Attribute' object has no attribute 'name'

Expected behavior

Not fail? I think

Pylint version

pylint 2.12.2
astroid 2.9.0
Python 3.8.10 (default, Mar 15 2022, 12:22:08) 
[GCC 9.4.0]
@FPENGKAR FPENGKAR added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label May 9, 2022
@Pierre-Sassoulas Pierre-Sassoulas added the Crash 💥 A bug that makes pylint crash label May 9, 2022
@Pierre-Sassoulas
Copy link
Member

Thank you for opening the issue. Could you maybe provide the code extract that made pylint crash ?

@FPENGKAR
Copy link
Author

FPENGKAR commented May 9, 2022

No, I'm afraid that is not possible. However, it seems I managed to handle the bug by changing:

for input_output in mydictionary.items();

to:
for inputkey,outputkey in mydictionary.items():

So it seems it doesn't like using a tuple?

@jacobtylerwalls
Copy link
Member

Reproducer:

class A:
  pass

my_dict = {}
a = A()
for input_output in my_dict.items():
  a.input_output = input_output
  my_dict[a.input_output[0]]

@jacobtylerwalls jacobtylerwalls removed the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label May 9, 2022
@jacobtylerwalls jacobtylerwalls self-assigned this May 11, 2022
@jacobtylerwalls jacobtylerwalls added this to the 2.13.9 milestone May 11, 2022
@jacobtylerwalls jacobtylerwalls added Needs backport Needs to be cherry-picked on the current patch version by a pylint's maintainer and removed Needs backport Needs to be cherry-picked on the current patch version by a pylint's maintainer labels May 11, 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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants