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

AttributeError: 'Call' object has no attribute 'name' #4837

Closed
gtristan opened this issue Aug 13, 2021 · 1 comment · Fixed by #4847
Closed

AttributeError: 'Call' object has no attribute 'name' #4837

gtristan opened this issue Aug 13, 2021 · 1 comment · Fixed by #4847
Labels
Bug 🪲 Crash 💥 A bug that makes pylint crash
Milestone

Comments

@gtristan
Copy link

gtristan commented Aug 13, 2021

Bug description

This is similar but distinct from issue #4439.

Here is a reduced test case, I was able to concoct this after running pylint with modified checkers/classes.py and tracing the asteroid nodes being checked in _check_unused_private_attributes().

class Pony:
    __defaults = {}
    __defaults_set = False

    def __init__(self, value):
        self.value = value

    def __init_defaults(self):

        if not self.__defaults_set:
            type(self).__defaults = { "fur": "pink" }
            type(self).__defaults_set = True


    def __get_fur_color(self):
        color = lookup_attribute(self.__defaults, "fur")
        return color


def lookup_attribute(mapping, key):
    return mapping[key]

Possible fix

I think the crash is essentially caused by NodeNG.node_of_classes() yielding attributes passed through function calls, and it seems that pylint's _check_unused_private_attributes() is unprepared for this outcome.

The yielded astroid.AssignAttr and astroid.Attribute should have the type of the expr object checked before expecting the expression to be a named expression.

Command used

pylint test.py

Pylint output

Here is the stack trace generated by linting the test case:

Exception on node <ClassDef.Pony l.2 at 0x7f4029878280> in file '/home/tristan/linting-issue.py'
Traceback (most recent call last):
  File "/home/tristan/.local/bin/pylint", line 8, in <module>
    sys.exit(run_pylint())
  File "/home/tristan/.local/lib/python3.9/site-packages/pylint/__init__.py", line 24, in run_pylint
    PylintRun(sys.argv[1:])
  File "/home/tristan/.local/lib/python3.9/site-packages/pylint/lint/run.py", line 384, in __init__
    linter.check(args)
  File "/home/tristan/.local/lib/python3.9/site-packages/pylint/lint/pylinter.py", line 975, in check
    self._check_files(
  File "/home/tristan/.local/lib/python3.9/site-packages/pylint/lint/pylinter.py", line 1009, in _check_files
    self._check_file(get_ast, check_astroid_module, name, filepath, modname)
  File "/home/tristan/.local/lib/python3.9/site-packages/pylint/lint/pylinter.py", line 1035, in _check_file
    check_astroid_module(ast_node)
  File "/home/tristan/.local/lib/python3.9/site-packages/pylint/lint/pylinter.py", line 1172, in check_astroid_module
    retval = self._check_astroid_module(
  File "/home/tristan/.local/lib/python3.9/site-packages/pylint/lint/pylinter.py", line 1217, in _check_astroid_module
    walker.walk(ast_node)
  File "/home/tristan/.local/lib/python3.9/site-packages/pylint/utils/ast_walker.py", line 77, in walk
    self.walk(child)
  File "/home/tristan/.local/lib/python3.9/site-packages/pylint/utils/ast_walker.py", line 79, in walk
    callback(astroid)
  File "/home/tristan/.local/lib/python3.9/site-packages/pylint/checkers/classes.py", line 904, in leave_classdef
    self._check_unused_private_attributes(node)
  File "/home/tristan/.local/lib/python3.9/site-packages/pylint/checkers/classes.py", line 983, in _check_unused_private_attributes
    assign_attr.expr.name == "cls"
AttributeError: 'Call' object has no attribute 'name'

Expected behavior

No crash, properly report if private class attributes are unused.

Pylint version

pylint 2.9.6
astroid 2.6.6
Python 3.9.2 (default, Feb 28 2021, 17:03:44) 

I've also tested this with python 3.8 and had the same results.

OS / Environment

I've seen this on fedora 32 and on debian 11.

Additional dependencies

No response

@gtristan gtristan added Bug 🪲 Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Aug 13, 2021
@Pierre-Sassoulas Pierre-Sassoulas added Crash 💥 A bug that makes pylint crash Needs astroid update Needs an astroid update (probably a release too) before being mergable and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling Needs astroid update Needs an astroid update (probably a release too) before being mergable labels Aug 13, 2021
@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.10.0 milestone Aug 13, 2021
@Pierre-Sassoulas
Copy link
Member

Thank you for taking the time to report this. Love the example with default pink ponyz.

gtristan added a commit to apache/buildstream that referenced this issue Aug 13, 2021
…systems

This also removes the `pytest-pip8` and `pytest-pylint` pytest plugin
dependencies, as we will be adopting the strategy from master and running
the linter directly instead from now on.

We now pin pylint at version 2.8.3, due to an upstream pylint crash introduced
in 2.9.x, see:

  #1496
  pylint-dev/pylint#4837
Pierre-Sassoulas added a commit to Pierre-Sassoulas/pylint that referenced this issue Aug 15, 2021
It was already fixed in master, we need to release 2.10.0.
Pierre-Sassoulas added a commit that referenced this issue Aug 15, 2021
It was already fixed in master, we need to release 2.10.0.
gtristan added a commit to apache/buildstream that referenced this issue Aug 16, 2021
…systems

This also removes the `pytest-pip8` and `pytest-pylint` pytest plugin
dependencies, as we will be adopting the strategy from master and running
the linter directly instead from now on.

We now pin pylint at version 2.8.3, due to an upstream pylint crash introduced
in 2.9.x, see:

  #1496
  pylint-dev/pylint#4837
gtristan added a commit to apache/buildstream that referenced this issue Aug 18, 2021
…systems

This also removes the `pytest-pip8` and `pytest-pylint` pytest plugin
dependencies, as we will be adopting the strategy from master and running
the linter directly instead from now on.

We now pin pylint at version 2.8.3, due to an upstream pylint crash introduced
in 2.9.x, see:

  #1496
  pylint-dev/pylint#4837
gtristan added a commit to apache/buildstream that referenced this issue Aug 24, 2021
jjardon pushed a commit to jjardon/buildstream-1 that referenced this issue Jan 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🪲 Crash 💥 A bug that makes pylint crash
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants