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

incorrect error reported for numpy #3640

Closed
lhfriedman opened this issue May 21, 2020 · 2 comments · Fixed by pylint-dev/astroid#830 or PennyDreadfulMTG/Penny-Dreadful-Tools#8447
Closed
Assignees
Labels
Bug 🪲 Needs astroid Brain 🧠 Needs a brain tip in astroid (then an astroid upgrade)

Comments

@lhfriedman
Copy link

Steps to reproduce

  1. Use this test code in file flat_iter.py
    import numpy as np
    a_0 = np.array([[1, 2, 3]])
    print(a_0)
    a_0.flat[1] = 2**14
    print(a_0)

[[1 2 3]]
[[ 1 16384 3]]

pylint flat_iter.py
************* Module flat_iter
flat_iter.py:14:0: E1137: 'a_0.flat' does not support item assignment (unsupported-assignment-operation)


Your code has been rated at 0.00/10

Current behavior

reports E1137

Expected behavior

ignores correct python code

pylint --version output

pylint 2.5.0
astroid 2.4.0
Python 3.7.7 (default, May 6 2020, 11:45:54) [MSC v.1916 64 bit (AMD64)]

@PCManticore PCManticore added Needs astroid Brain 🧠 Needs a brain tip in astroid (then an astroid upgrade) Bug 🪲 labels May 28, 2020
@brycepg
Copy link
Contributor

brycepg commented Jun 16, 2020

For some reason astroid is inferring the array as an ndarray. Since ndarray.flat is an iterable the above error code was produced.

import astroid

a_0_astroid = astroid.extract_node(
"""
import numpy as np
a_0 = np.array([[1, 2, 3]])
print(a_0)
a_0.flat[1] = 2**14
a_0 #@
""")
[nd_astroid] = a_0_astroid.inferred()
print(nd_astroid)

<Instance of .ndarray at 0x2253675315944>

If someone wanted to check how numpy.array is assigned in the numpy source code, that may help us understand how astroid is messing up.

@hippo91 hippo91 self-assigned this Aug 5, 2020
@hippo91
Copy link
Contributor

hippo91 commented Aug 5, 2020

@brycepg ,

the problem is due to the fact that the flat attribute of numpy.ndarray is said to be None in the corresponding brain. (brain_numpy_ndarray.py).
I'll try to fix this ASAP.

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
4 participants