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 assignment-from-no-return #2435

Closed
cdeil opened this issue Aug 22, 2018 · 3 comments
Closed

False positive E1111 assignment-from-no-return #2435

cdeil opened this issue Aug 22, 2018 · 3 comments
Labels
Bug 🪲 Needs astroid Brain 🧠 Needs a brain tip in astroid (then an astroid upgrade)

Comments

@cdeil
Copy link

cdeil commented Aug 22, 2018

I'm getting false positives E1111 assignment-from-no-return from pylint for this project: https://github.com/gammapy/gammapy

Here's a minimal example to reproduce:

import numpy as np


class MyArray(np.ndarray):
    pass


a = np.ndarray((2,), buffer=np.array([1, 2, 3]), offset=np.int_().itemsize, dtype=int)
b = a.flatten()
print(b)

c = MyArray((2,), buffer=np.array([1, 2, 3]), offset=np.int_().itemsize, dtype=int)
d = c.flatten()
print(d)

The error reported is this:

$ pylint test.py -E
************* Module test
test.py:8:56: E1120: No value for argument 'value' in constructor call (no-value-for-parameter)
test.py:12:53: E1120: No value for argument 'value' in constructor call (no-value-for-parameter)
test.py:13:0: E1111: Assigning to function call which doesn't return (assignment-from-no-return)

The E1111 is a false positive, c.flatten() does return:

$ python test.py 
[2 3]
[2 3]

This is for current astroid and pylint master, which reports like this:

$ pylint --version
pylint 2.2.0
astroid 2.0.4
Python 3.6.0 | packaged by conda-forge | (default, Feb 10 2017, 07:08:35) 
[GCC 4.2.1 Compatible Apple LLVM 7.3.0 (clang-703.0.31)]

It's weird that the same false positive doesn't appear for the equivalent a.flatten() call.

Also, the message is cryptic:

Assigning to function call which doesn't return

I'm not assigning to a function call.
I'm making a function call c.flatten() and assign the return value to a local variable d.

@PCManticore
Copy link
Contributor

Thanks for reporting the issue!

This is happening because the brain functions we have for numpy don't return anything, which confuses this check. Also agree on the fact that the message is cryptic, going to update it to something easier to understand.

@PCManticore PCManticore added Bug 🪲 Needs astroid Brain 🧠 Needs a brain tip in astroid (then an astroid upgrade) labels Aug 23, 2018
@nils-wisiol
Copy link

This happens also with numpy's sign function, as can be seen in this minimal example:

from numpy import sign

x = sign(-1)
print(x)

pylint says test.py:3:0: E1111: Assigning result of a function call, where the function has no return (assignment-from-no-return)

pip freeze:

astroid==2.1.0
isort==4.3.4
lazy-object-proxy==1.3.1
mccabe==0.6.1
numpy==1.16.0
pkg-resources==0.0.0
pylint==2.2.2
six==1.12.0
typed-ast==1.2.0
wrapt==1.11.1

nils-wisiol added a commit to nils-wisiol/pypuf that referenced this issue Jan 25, 2019
@PCManticore
Copy link
Contributor

This is fixed in the master branch of astroid, just found out it's a duplicate of #2694 which was closed just today.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🪲 Needs astroid Brain 🧠 Needs a brain tip in astroid (then an astroid upgrade)
Projects
None yet
Development

No branches or pull requests

3 participants