pylint icon indicating copy to clipboard operation
pylint copied to clipboard

False positives when using methods that pylint saw being once overridden at instance level

Open jstasiak opened this issue 9 years ago • 1 comments

Steps to reproduce

1 Have the following file (xyz.py):

class A:
    def get_stuff(self, x):
        return x


def test1():
    def g():
        pass
    a = A()
    a.get_stuff = g


def test2():
    a = A()
    value = a.get_stuff(1)

2 Run pylint -f parseable xyz 2> /dev/null | grep "\[E"

Current behavior

Pylint detects errors where it shouldn't:

xyz.py:15: [E1111(assignment-from-no-return), test2] Assigning to function call which doesn't return
xyz.py:15: [E1121(too-many-function-args), test2] Too many positional arguments for function call

Expected behavior

No errors reported (well, maybe pylint could detect incompatible type on a.get_stuff = g assignment)

pylint --version output

No config file found, using default configuration
pylint 1.6.4, 
astroid 1.4.8
Python 3.5.2 (default, Jun 29 2016, 13:43:58) 
[GCC 4.2.1 Compatible Apple LLVM 7.3.0 (clang-703.0.31)]

Keywords for visibility: type inference

jstasiak avatar Sep 30 '16 11:09 jstasiak

I looked into this issue and it's decidedly an inference issue in astroid.

In the assignment-from-no-return case the inference returned in function_node = safe_infer(node.value.func) references <FunctionDef.g l.7 at 0x111e19370>.

Similarly, in the too-many-function-args, the inference returned in called = safe_infer(node.func) references <FunctionDef.g l.7 at 0x10225b0a0>

Both of these should've returned <ClassDef.A l.1 at 0x10ab643d0>. Astroid probably has this implementation to handle some other cases when getting the overriding value is correct, but in this case this isn't the correct behavior.

clavedeluna avatar Nov 26 '22 12:11 clavedeluna