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: calling super on bases base class is shown as error #2903

Closed
Bergiu opened this issue May 4, 2019 · 11 comments · Fixed by #6956
Closed

False positive: calling super on bases base class is shown as error #2903

Bergiu opened this issue May 4, 2019 · 11 comments · Fixed by #6956
Assignees
Labels
False Positive 🦟 A message is emitted but nothing is wrong with the code
Milestone

Comments

@Bergiu
Copy link

Bergiu commented May 4, 2019

Steps to reproduce

  1. Make an empty folder and create the file test.py with this content:
    image
  2. pylint test.py

Current behavior

Executing the code works, but a false positive error is shown.

E1003: Bad first argument 'B' given to super() (bad-super-call)

Expected behavior

Pylint shouldn't show this error.

pylint --version output

astroid 2.2.5
Python 3.7.3 (default, Mar 26 2019, 21:43:19) 
[GCC 8.2.1 20181127]
@PCManticore
Copy link
Contributor

@Bergiu At line 17 you are supposed to pass C to super(), not B. By passing Byou basically ask a MRO navigation starting from B instead of C for finding thesomething` method.

@PCManticore PCManticore added the Invalid Not a bug, already exists or already fixed label May 5, 2019
@Bergiu
Copy link
Author

Bergiu commented May 6, 2019

But I want it to start at B, so that I get the something method from A.

@Bergiu
Copy link
Author

Bergiu commented May 7, 2019

Can you reopen the issue @PCManticore, or am I getting something wrong?

@maxhillis
Copy link

What is the difference between lines 15 and 17? Why is 15 ok and 17 bad?

@Bergiu
Copy link
Author

Bergiu commented Apr 15, 2020

the method is called in line 17.

@maxhillis
Copy link

No sorry I mean from the perspective of pylint. If 17 is flagged then 15 should be too. I was trying to do the same thing you were and I couldn't understand why pylint considered this bad code. It works as I intend but I have been having trouble finding why its considered bad practice

@Bergiu
Copy link
Author

Bergiu commented Apr 15, 2020

Yes

@krystean
Copy link

Came across this while making a project which has the same structure as your code and can't understand why it's considered a bad-super-call. Isn't that the use of super?

@DanielNoord
Copy link
Collaborator

Re-opening this because we found ourselves that it is probably better to do consider this a false positive. If anybody feels like implementing this I think we would be more than happy to review and put this in one of the next releases!

For reference see the small discussion in:
pylint-dev/astroid#1217 (comment)

@DanielNoord DanielNoord reopened this Nov 6, 2021
@cdce8p cdce8p added False Positive 🦟 A message is emitted but nothing is wrong with the code and removed Invalid Not a bug, already exists or already fixed labels Nov 6, 2021
@cdce8p
Copy link
Member

cdce8p commented Nov 6, 2021

For reference and testing:

class Parent:
    def __init__(self):
        print("Parent")

class Child(Parent):
    def __init__(self):
        print("Child")
        super().__init__()

class GrandChild(Child):
    def __init__(self):
        print("Grandchild")
        super(Child, self).__init__()  # should not emit 'bad-super-call'!

GrandChild()

@cdce8p
Copy link
Member

cdce8p commented Nov 7, 2021

For reference: discussion about future usefulness of check: pylint-dev/astroid#1217 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

6 participants