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 E1111 when overriding an inherited method #4220

Closed
exquo opened this issue Mar 9, 2021 · 1 comment · Fixed by pylint-dev/astroid#1151
Closed

False positive E1111 when overriding an inherited method #4220

exquo opened this issue Mar 9, 2021 · 1 comment · Fixed by pylint-dev/astroid#1151
Labels
False Positive 🦟 A message is emitted but nothing is wrong with the code

Comments

@exquo
Copy link

exquo commented Mar 9, 2021

Steps to reproduce

# pylint: disable=no-self-use

class A:
    def f(self):
        return 42


class B(A):
    def __init__(self):
        self.a = A()
        result = self.a.f()
        print(result)

    def f(self):
        pass


res = B().a.f()

Current behavior

$ pylint -E assignment_from_no_return.py
************* Module assignment_from_no_return
assignment_from_no_return.py:11:8: E1111: Assigning result of a function call, where the function has no return (assignment-from-no-return)
assignment_from_no_return.py:18:0: E1111: Assigning result of a function call, where the function has no return (assignment-from-no-return)

Expected behavior

No errors.

pylint --version output

pylint 2.7.2
astroid 2.5.1
Python 3.7.3 (default, Jul 25 2020, 13:03:44)
[GCC 8.3.0]

Additional info

This happens only for very particular conditions:

  • Child class has an attribute which is an instance of the parent class
    and
  • Child class overrides parent's method, which does not return, with a method that does return

In other words, there is no error reported if:

  • a is not an attribute of B (self.a changed to a)
    or
  • B does not inherit from A (class B(object): ...)

Also, if a third subclass is defined that overrides f again, it does not get this error:

class C(B):
    def __init__(self):
        self.a = A()
        self.b = B()
        res = self.a.f()
        res = self.b.a.f()
    def f(self):
        return -42

Somewhat related:
pylint-dev/astroid#1683 (latest defined method is considered)
#1123 (method overriden on object's instance)
#3218 (the "opposite" of this: the child's method returns, the parent's does not)

P.S. Thanks for maintaining pylint!

@Pierre-Sassoulas Pierre-Sassoulas added the False Positive 🦟 A message is emitted but nothing is wrong with the code label Mar 21, 2021
@Pierre-Sassoulas
Copy link
Member

Thank you for opening the issue, I can reproduce this.

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.

2 participants