Skip to content

Missing member hint fails when object has duplicated bases #4687

@doranid

Description

@doranid

Steps to reproduce

Given a file b.py:

# pylint: disable=C0114, C0115, R0205, E0241, C0116, W0104
class Klass(object, object):
    def get(self):
        self._non_existent_attribute

Current behavior

Result of pylint a.py:

➜  d pylint b.py
Exception on node <Attribute._non_existent_attribute l.7 at 0x10e80d898> in file 'b.py'
Traceback (most recent call last):
  File "bin/pylint", line 8, in <module>
    sys.exit(run_pylint())
  File "pylint/__init__.py", line 24, in run_pylint
    PylintRun(sys.argv[1:])
  File "pylint/lint/run.py", line 384, in __init__
    linter.check(args)
  File "pylint/lint/pylinter.py", line 974, in check
    self.get_ast, self._iterate_file_descrs(files_or_modules)
  File "pylint/lint/pylinter.py", line 1007, in _check_files
    self._check_file(get_ast, check_astroid_module, name, filepath, modname)
  File "pylint/lint/pylinter.py", line 1033, in _check_file
    check_astroid_module(ast_node)
  File "pylint/lint/pylinter.py", line 1171, in check_astroid_module
    ast_node, walker, rawcheckers, tokencheckers
  File "pylint/lint/pylinter.py", line 1215, in _check_astroid_module
    walker.walk(ast_node)
  File "pylint/utils/ast_walker.py", line 77, in walk
    self.walk(child)
  File "pylint/utils/ast_walker.py", line 77, in walk
    self.walk(child)
  File "pylint/utils/ast_walker.py", line 77, in walk
    self.walk(child)
  [Previous line repeated 1 more time]
  File "pylint/utils/ast_walker.py", line 74, in walk
    callback(astroid)
  File "pylint/checkers/typecheck.py", line 1033, in visit_attribute
    msg, hint = self._get_nomember_msgid_hint(node, owner)
  File "pylint/checkers/typecheck.py", line 1055, in _get_nomember_msgid_hint
    self.config.missing_member_max_choices,
  File "pylint/checkers/typecheck.py", line 244, in _missing_member_hint
    names = _similar_names(owner, attrname, distance_threshold, max_choices)
  File "pylint/checkers/typecheck.py", line 222, in _similar_names
    names = _node_names(owner)
  File "functools.py", line 807, in wrapper
    return dispatch(args[0].__class__)(*args, **kw)
  File "pylint/checkers/typecheck.py", line 189, in _
    mro = node.mro()[1:]
  File "astroid/scoped_nodes.py", line 2983, in mro
    return self._compute_mro(context=context)
  File "astroid/scoped_nodes.py", line 2971, in _compute_mro
    unmerged_mro = list(clean_duplicates_mro(unmerged_mro, self, context))
  File "astroid/scoped_nodes.py", line 157, in clean_duplicates_mro
    context=context,
astroid.exceptions.DuplicateBasesError: Duplicates found in MROs (Klass), (object), (object), (object, object) for <ClassDef.Klass l.2 at 0x10e80d470>.

Expected behavior

Should not fail hard.

pylint --version output

pylint 2.9.3
astroid 2.6.2
Python 3.6.12 (default, Feb 6 2021, 10:30:58)
[GCC Apple LLVM 12.0.0 (clang-1200.0.32.29)]


Metadata

Metadata

Assignees

No one assigned

    Labels

    Blocker 🙅Blocks the next releaseCrash 💥A bug that makes pylint crash

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions