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

Don't show astroid.DuplicateBasesError for attribute access #4317

Merged
merged 1 commit into from
Apr 8, 2021
Merged

Don't show astroid.DuplicateBasesError for attribute access #4317

merged 1 commit into from
Apr 8, 2021

Conversation

cdce8p
Copy link
Member

@cdce8p cdce8p commented Apr 7, 2021

Steps

  • Add yourself to CONTRIBUTORS if you are a new contributor.
  • Add a ChangeLog entry describing what your PR does.
  • If it's a new feature or an important bug fix, add a What's New entry in
    doc/whatsnew/<current release.rst>.
  • Write a good description on what the PR does.

Description

Previously an attribute access to a class which has duplicate bases would result in an astroid.DuplicateBasesError.
Note: The error for duplicate-bases was / is still printed.

Without MR

************* Module functional.d.duplicate_bases
tests/functional/d/duplicate_bases.py:5:0: E0241: Duplicate bases for class 'Duplicates' (duplicate-bases)
Traceback (most recent call last):
  File "/Users/.../pylint/venv-39_link/bin/pylint", line 33, in <module>
    sys.exit(load_entry_point('pylint', 'console_scripts', 'pylint')())
  File "/Users/.../pylint/pylint/__init__.py", line 24, in run_pylint
    PylintRun(sys.argv[1:])
  File "/Users/.../pylint/pylint/lint/run.py", line 358, in __init__
    linter.check(args)
  File "/Users/.../pylint/pylint/lint/pylinter.py", line 877, in check
    self._check_files(
  File "/Users/.../pylint/pylint/lint/pylinter.py", line 911, in _check_files
    self._check_file(get_ast, check_astroid_module, name, filepath, modname)
  File "/Users/.../pylint/pylint/lint/pylinter.py", line 937, in _check_file
    check_astroid_module(ast_node)
  File "/Users/.../pylint/pylint/lint/pylinter.py", line 1071, in check_astroid_module
    retval = self._check_astroid_module(
  File "/Users/.../pylint/pylint/lint/pylinter.py", line 1116, in _check_astroid_module
    walker.walk(ast_node)
  File "/Users/.../pylint/pylint/utils/ast_walker.py", line 75, in walk
    self.walk(child)
  File "/Users/.../pylint/pylint/utils/ast_walker.py", line 75, in walk
    self.walk(child)
  File "/Users/.../pylint/pylint/utils/ast_walker.py", line 75, in walk
    self.walk(child)
  File "/Users/.../pylint/pylint/utils/ast_walker.py", line 72, in walk
    callback(astroid)
  File "/Users/.../pylint/pylint/checkers/typecheck.py", line 981, in visit_attribute
    for n in owner.getattr(node.attrname)
  File "/Users/.../astroid/astroid/scoped_nodes.py", line 2444, in getattr
    result = [self.special_attributes.lookup(name)]
  File "/Users/.../astroid/astroid/interpreter/objectmodel.py", line 124, in lookup
    return getattr(self, IMPL_PREFIX + name)
  File "/Users/.../astroid/astroid/interpreter/objectmodel.py", line 426, in attr___mro__
    mro = self._instance.mro()
  File "/Users/.../astroid/astroid/scoped_nodes.py", line 2937, in mro
    return self._compute_mro(context=context)
  File "/Users/.../astroid/astroid/scoped_nodes.py", line 2926, in _compute_mro
    unmerged_mro = list(clean_duplicates_mro(unmerged_mro, self, context))
  File "/Users/.../astroid/astroid/scoped_nodes.py", line 113, in clean_duplicates_mro
    raise exceptions.DuplicateBasesError(
astroid.exceptions.DuplicateBasesError: Duplicates found in MROs (Duplicates), (str, object), (str, object), (str, str) for <ClassDef.Duplicates l.5 at 0x7fb0c698ffa0>.

With

************* Module functional.d.duplicate_bases
tests/functional/d/duplicate_bases.py:5:0: E0241: Duplicate bases for class 'Duplicates' (duplicate-bases)

Type of Changes

Type
🐛 Bug fix

@cdce8p cdce8p requested a review from Pierre-Sassoulas April 7, 2021 23:17
@cdce8p cdce8p added this to the 2.7.5 milestone Apr 7, 2021
@coveralls
Copy link

Coverage Status

Coverage increased (+0.001%) to 91.61% when pulling 58390aa on cdce8p:fix-duplicate-bases-error into 8b18d91 on PyCQA:master.

Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice fix ! Strange that no one opened an issue for this ? I added a suggestion but feel free to merge.

@@ -985,6 +985,8 @@ def visit_attribute(self, node):
continue
except AttributeError:
continue
except astroid.DuplicateBasesError:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
except astroid.DuplicateBasesError:
except astroid.DuplicateBasesError:
# See https://github.com/PyCQA/pylint/pull/4317

Copy link
Member Author

@cdce8p cdce8p Apr 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this is worth it. For one, you can get this information via git blame. Additionally the added test will catch if it's missing.

@Pierre-Sassoulas Pierre-Sassoulas added the Crash 💥 A bug that makes pylint crash label Apr 8, 2021
@cdce8p cdce8p merged commit 5e1928b into pylint-dev:master Apr 8, 2021
@cdce8p cdce8p deleted the fix-duplicate-bases-error branch April 8, 2021 11:21
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 this pull request may close these issues.

3 participants