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

Exception thrown when using private class method #4638

Closed
bugale opened this issue Jun 30, 2021 · 1 comment · Fixed by #4642
Closed

Exception thrown when using private class method #4638

bugale opened this issue Jun 30, 2021 · 1 comment · Fixed by #4642
Assignees
Labels
Blocker 🙅 Blocks the next release Crash 💥 A bug that makes pylint crash
Milestone

Comments

@bugale
Copy link

bugale commented Jun 30, 2021

Steps to reproduce

Given a file test.py:

"""Bla"""

class Bla:
    """Bla"""
    def __init__(self):
        type(self).__a()

    @classmethod
    def __a(cls):
        pass

Current behavior

Result of pylint a.py:

C:\temp>py -3 -m pylint test.py
Exception on node <ClassDef.Bla l.3 at 0x1255a3b6dc0> in file 'C:\temp\test.py'
Traceback (most recent call last):
  File "C:\Program Files\Python39\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Program Files\Python39\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Program Files\Python39\lib\site-packages\pylint\__main__.py", line 9, in <module>
    pylint.run_pylint()
  File "C:\Program Files\Python39\lib\site-packages\pylint\__init__.py", line 24, in run_pylint
    PylintRun(sys.argv[1:])
  File "C:\Program Files\Python39\lib\site-packages\pylint\lint\run.py", line 384, in __init__
    linter.check(args)
  File "C:\Program Files\Python39\lib\site-packages\pylint\lint\pylinter.py", line 973, in check
    self._check_files(
  File "C:\Program Files\Python39\lib\site-packages\pylint\lint\pylinter.py", line 1007, in _check_files
    self._check_file(get_ast, check_astroid_module, name, filepath, modname)
  File "C:\Program Files\Python39\lib\site-packages\pylint\lint\pylinter.py", line 1033, in _check_file
    check_astroid_module(ast_node)
  File "C:\Program Files\Python39\lib\site-packages\pylint\lint\pylinter.py", line 1170, in check_astroid_module
    retval = self._check_astroid_module(
  File "C:\Program Files\Python39\lib\site-packages\pylint\lint\pylinter.py", line 1215, in _check_astroid_module
    walker.walk(ast_node)
  File "C:\Program Files\Python39\lib\site-packages\pylint\utils\ast_walker.py", line 77, in walk
    self.walk(child)
  File "C:\Program Files\Python39\lib\site-packages\pylint\utils\ast_walker.py", line 79, in walk
    callback(astroid)
  File "C:\Program Files\Python39\lib\site-packages\pylint\checkers\classes.py", line 901, in leave_classdef
    self._check_unused_private_members(node)
  File "C:\Program Files\Python39\lib\site-packages\pylint\checkers\classes.py", line 914, in _check_unused_private_members
    and attribute.expr.name in ("self", node.name)
AttributeError: 'Call' object has no attribute 'name'

Expected behavior

************* Module test
test.py:3:0: R0903: Too few public methods (0/2) (too-few-public-methods)

------------------------------------------------------------------
Your code has been rated at 8.00/10 (previous run: 2.00/10, +6.00)

pylint --version output

Result of pylint --version output:

C:\temp>py -3 -m pylint --version
pylint 2.9.1
astroid 2.6.2
Python 3.9.5 (tags/v3.9.5:0a7dcbd, May  3 2021, 17:27:52) [MSC v.1928 64 bit (AMD64)]

The issue doesn't reproduce on version 2.8.3
It started reproducing on 2.9.0 and still happens in the latest prerelease version

@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.9.2 milestone Jun 30, 2021
@Pierre-Sassoulas Pierre-Sassoulas added Blocker 🙅 Blocks the next release Crash 💥 A bug that makes pylint crash labels Jun 30, 2021
@Pierre-Sassoulas Pierre-Sassoulas self-assigned this Jun 30, 2021
@cdce8p
Copy link
Member

cdce8p commented Jun 30, 2021

@bugale You should be able to use Bla.__a() or even self.__a() instead. We are currently working on a fix for type(self)

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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants