Skip to content

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

Closed
@kiefermat

Description

@kiefermat

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.

Metadata

Metadata

Assignees

Labels

Enhancement ✨Improvement to a componentFalse Positive 🦟A message is emitted but nothing is wrong with the code

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions