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

too-many-ancestors when inheriting from collections.abc.MutableSequence #4415

Closed
Alphadelta14 opened this issue Apr 28, 2021 · 1 comment · Fixed by #4416
Closed

too-many-ancestors when inheriting from collections.abc.MutableSequence #4415

Alphadelta14 opened this issue Apr 28, 2021 · 1 comment · Fixed by #4416
Assignees
Labels
Enhancement ✨ Improvement to a component False Positive 🦟 A message is emitted but nothing is wrong with the code
Milestone

Comments

@Alphadelta14
Copy link

Simply inheriting from collections.abc.MutableSequence generates a too-many-ancestors refactoring warning.
Yes, it does have that many ancestors, but I would consider only classes from the stdlib that are actually inherited by user code to be counted towards max ancestors.
And yes, I can disable this error in this case, or increase the max ancestors count, but it feels wrong to do that when just using the collections hierarchy for its intended purpose.

Steps to reproduce

For a minimal MutableSequence implemented, ancestor.py:

from collections.abc import MutableSequence


class ItemSequence(MutableSequence):
    """Minimal MutableSequence."""
    def __getitem__(self, key):
        return key

    def __setitem__(self, key, value):
        _ = key, value

    def __delitem__(self, key):
        _ = key

    def insert(self, index, value):
        _ = index, value

    def __len__(self):
        return 1

pylint ancestor.py returns:
ancestor.py:4:0: R0901: Too many ancestors (8/7) (too-many-ancestors)

Expected behavior

Inheriting from a stdlib class shouldn't generate a Refactor warning.

pylint --version output

Result of pylint --version output:

pylint 2.7.4
astroid 2.5.2
Python 3.7.7 (default, Aug  8 2019, 00:00:00) 
[GCC 8.3.1 20190311 (Red Hat 8.3.1-3)]
@Pierre-Sassoulas Pierre-Sassoulas added Enhancement ✨ Improvement to a component False Positive 🦟 A message is emitted but nothing is wrong with the code labels Apr 28, 2021
@Pierre-Sassoulas
Copy link
Member

I agree. This is a side effect of a better comprehension of stdlib class in astroid.

@cdce8p cdce8p mentioned this issue Apr 28, 2021
4 tasks
@cdce8p cdce8p self-assigned this Apr 28, 2021
@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.9.0 milestone Jun 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement ✨ Improvement to a component False Positive 🦟 A message is emitted but nothing is wrong with the code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants