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

Mention class lacking implementation in abstract-method message #7124

Closed
harupy opened this issue Jul 4, 2022 · 5 comments · Fixed by #7503
Closed

Mention class lacking implementation in abstract-method message #7124

harupy opened this issue Jul 4, 2022 · 5 comments · Fixed by #7503
Labels
Documentation 📗 Good first issue Friendly and approachable by new contributors Hacktoberfest Needs PR This issue is accepted, sufficiently specified and now needs an implementation

Comments

@harupy
Copy link
Contributor

harupy commented Jul 4, 2022

Bug description

from abc import abstractmethod, ABCMeta


class WildAnimal(metaclass=ABCMeta):
    @abstractmethod
    def make_sound(self):
        pass


class Panther(WildAnimal):
    def make_sound(self):
        raise NotImplementedError("Panther")


class PantherChild(Panther):
    pass

pylint raise the following error against the code above?

a.py:15:0: W0223: Method 'make_sound' is abstract in class 'Panther' but is not overridden (abstract-method)

Is this a false positive?

Configuration

No response

Command used

# Save the code above as a.py and then run:
docker run --rm -w /app -v $(pwd)/a.py:/app/a.py python:3.7 bash -c "pip install pylint && pylint --disable=C,R a.py"

Pylint output

************* Module a
a.py:15:0: W0223: Method 'make_sound' is abstract in class 'Panther' but is not overridden (abstract-method)

Expected behavior

pylint should not raise abstract-method because make_sound is overridden in Panther?

Pylint version

3.7.13

OS / Environment

No response

Additional dependencies

No response

@harupy harupy added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Jul 4, 2022
@jacobtylerwalls
Copy link
Member

It's not overridden in PantherChild, because it's reported on line 15. We could add the child class in the message output, though.

@jacobtylerwalls jacobtylerwalls added Good first issue Friendly and approachable by new contributors Documentation 📗 and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Jul 4, 2022
@jacobtylerwalls jacobtylerwalls changed the title False positive abstract-method? Mention class lacking implementation in abstract-method message Jul 4, 2022
@Pierre-Sassoulas Pierre-Sassoulas added this to Todo in Better error messages via automation Jul 4, 2022
@Pierre-Sassoulas Pierre-Sassoulas added the Needs PR This issue is accepted, sufficiently specified and now needs an implementation label Jul 4, 2022
@harupy
Copy link
Contributor Author

harupy commented Jul 4, 2022

@jacobtylerwalls Thanks for the comment! Is Panther.make_sound considered an abstract method since it contains raise NotImplementedError("Panther")?

@jacobtylerwalls
Copy link
Member

Exactly!

https://pylint.pycqa.org/en/latest/user_guide/messages/warning/abstract-method.html

@clavedeluna
Copy link
Collaborator

Happy to pick this up but just to verify, is the ask to change this output

Method 'make_sound' is abstract in class 'Panther' but is not overridden (abstract-method)

to this?

Method 'make_sound' is abstract in class 'Panther' but is not overridden in child class PantherChild (abstract-method)

?

@DanielNoord
Copy link
Collaborator

Yes! That makes the error a little bit more actionable!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation 📗 Good first issue Friendly and approachable by new contributors Hacktoberfest Needs PR This issue is accepted, sufficiently specified and now needs an implementation
Projects
Development

Successfully merging a pull request may close this issue.

5 participants