pylint icon indicating copy to clipboard operation
pylint copied to clipboard

False-negative E1101 no-member for function parameter

Open bersbersbers opened this issue 3 years ago • 3 comments

Is your issue fixed on the preview release?: pip install pylint astroid --pre -U --> no

Steps to reproduce

"""False-negative no-member."""


def _func(param=True):
    print(param.name)

Current behavior

No error.

Expected behavior

bug.py:5:11: E1101: Instance of 'bool' has no 'name' member (no-member)

pylint --version output

pylint 2.6.0
astroid 2.4.2
Python 3.8.6 (default, Sep 29 2020, 15:36:55) 
[GCC 7.5.0]

bersbersbers avatar Jan 29 '21 06:01 bersbersbers

Seems like it's working as intended, boolean do not have a name attribute. Am I missing something here ?

>>> b = True
>>> b.name
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'bool' object has no attribute 'name'

Pierre-Sassoulas avatar Feb 06 '21 11:02 Pierre-Sassoulas

You may be confusing this with #4047, which is about a false positive. This one is about a false negative. As you rightly say, the code does not run without error, so pylint should complain.

bersbersbers avatar Feb 06 '21 14:02 bersbersbers

DOesn't this build on either type inference or control flow? What if param is IHaveANameAttribute | bool? This seems like it fits mypy more than it fits us.

DanielNoord avatar Sep 22 '22 15:09 DanielNoord

What about the related

def _func(param : bool):
    print(param.name)

? This also has no no-member emitted (let me know if I should create a new issue for this).

pylint 2.15.5
astroid 2.12.12
Python 3.8.10 (default, Jun 22 2022, 20:18:18) 
[GCC 9.4.0]

KennyChenBasis avatar Nov 03 '22 18:11 KennyChenBasis

We could raise a no-member for the function that has True as a default param (original example), but we're probably never going to do anything with type information alone (@KennyChenBasis example). mypy does that and it does it well and faster than us. Even #4813 which is our official "become a discount mypy" issue is about taking the type information into account "when inference fail" not all the time.

Pierre-Sassoulas avatar Nov 04 '22 09:11 Pierre-Sassoulas

What's the agreement here? It seems like the PR that implemented the fix here was closed, so should this issue be closed as won't fix?

clavedeluna avatar Nov 28 '22 21:11 clavedeluna

I think we're going to have too much false positive if we don't wait for #4813, I'll add the blocked label.

Pierre-Sassoulas avatar Nov 28 '22 22:11 Pierre-Sassoulas