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

false positive too-many-ancestors if class inherits MutableMapping #4166

Closed
kiefermat opened this issue Mar 1, 2021 · 4 comments · Fixed by #4416
Closed

false positive too-many-ancestors if class inherits MutableMapping #4166

kiefermat opened this issue Mar 1, 2021 · 4 comments · Fixed by #4416
Assignees
Labels
Enhancement ✨ Improvement to a component False Positive 🦟 A message is emitted but nothing is wrong with the code

Comments

@kiefermat
Copy link

Steps to reproduce

Given a file a.py:

# pylint: disable=missing-docstring

from typing import Iterator, MutableMapping, Optional


class PylintTestMap(MutableMapping[str, str]):
    config: MutableMapping[str, str] = dict()

    def __getitem__(self, item: str) -> Optional[str]:
        return self.config.get(item)

    def __len__(self) -> int:
        return len(self.config)

    def __iter__(self) -> Iterator[str]:
        return iter(self.config)

    def __setitem__(self, key: str, value: str) -> None:
        self.config[key] = value

    def __delitem__(self, key: str) -> None:
        del self.config[key]

Current behavior

Result of pylint a.py:

************* Module a
a.py:7:0: R0901: Too many ancestors (8/7) (too-many-ancestors)

------------------------------------------------------------------
Your code has been rated at 9.23/10 (previous run: 9.23/10, +0.00)

Expected behavior

No warning about ancestors

pylint --version output

Result of pylint --version output:

pylint 2.7.2
astroid 2.5.1
Python 3.9.1

This behaviour has been introduced with pylint 2.7.2. pylint 2.7.1 does not show this warning.

@Pierre-Sassoulas
Copy link
Member

I think this is due to pylint-dev/astroid#916. Ie Mutable set has a long inheritance tree already "V => MutableSet => Set => Collection => Sized => Iterable => Container => Generic => object". We should probably start counting at the first non builtin type for too-many-ancestor.

@Pierre-Sassoulas Pierre-Sassoulas added Enhancement ✨ Improvement to a component False Positive 🦟 A message is emitted but nothing is wrong with the code labels Mar 1, 2021
@cdce8p cdce8p mentioned this issue Apr 28, 2021
4 tasks
@cdce8p cdce8p self-assigned this Apr 28, 2021
@winstxnhdw
Copy link
Contributor

Hey, I am getting this issue but with TypedDict from typing_extensions..

@Pierre-Sassoulas
Copy link
Member

I think it's because it's a non-builtin that we do not filter. As typing_extension is so widespread, maybe we could add it to the list here https://github.com/pylint-dev/pylint/pull/4416/files#diff-1fc8e30254a5d218a85ae17846638d3c9393d32819beec7d59d3fdbdea073c6aR178. Would you mind opening a merge request ?

@winstxnhdw
Copy link
Contributor

Happily #9167

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.

4 participants