astroid icon indicating copy to clipboard operation
astroid copied to clipboard

`assignment-from-no-return` considers the wrong method if ambiguous

Open cschramm opened this issue 6 years ago • 2 comments

Steps to reproduce

class Test():
    def test(self):
        pass

    def test(self):
        return True

A = Test().test()

Current behavior

5:4: E0102: method already defined line 2 (function-redefined)
5:4: R0201: Method could be a function (no-self-use)
8:0: E1111: Assigning to function call which doesn't return (assignment-from-no-return)

Expected behavior

5:4: E0102: method already defined line 2 (function-redefined)
5:4: R0201: Method could be a function (no-self-use)

pylint --version output

pylint 2.0.1
astroid 2.0.1
Python 3.6.5 (default, May 11 2018, 13:30:17) 
[GCC 7.3.0]

https://github.com/PyCQA/pylint/commit/9a9de854741e2f3d8f97cbace3d7de444acae340 adds that check for methods and https://github.com/PyCQA/astroid/commit/2aa27e9aed6ffcba4a61655e291e852ecd001549 causes the first of the definitions to be the only one that gets returned from infer_attribute. :negative_squared_cross_mark:

For ambiguous local functions, infer_name returns the correct definition. :heavy_check_mark: For ambiguous module functions, infer_attribute returns all definitions and safe_infer detects that ambiguity so that none of them get actually checked. :negative_squared_cross_mark: (I'd consider that an issue as well but it only causes false negatives, so it's not a huge one).

cschramm avatar Jul 23 '18 12:07 cschramm

Thanks for the report

I think I'll make the first result of ClassDef.getattr be the last defined name in a classdef

brycepg avatar Jul 24 '18 19:07 brycepg

FWIW, we've also hit this issue.

samertm avatar Sep 27 '18 21:09 samertm