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

Wrong error report (false positive) in numpy complex array value assignment #3322

Closed
wldhg opened this issue Dec 28, 2019 · 4 comments
Closed
Assignees

Comments

@wldhg
Copy link

wldhg commented Dec 28, 2019

When I pylinted a script contains numpy.complex array, E1137 appeared on correct code, and not in incorrect code.

Steps to reproduce

"""
This demonstrates numpy complex E1137 error
"""
# pylint: disable=C0103
# pylint: disable=W0702

import numpy as np

# Create a numpy complex array
comp_zeros = np.zeros(2, dtype=np.complex)
print(comp_zeros)

# Correct assignment
try:
    comp_zeros.imag[0] = 1
    comp_zeros.real[1] = 2
except:
    print("Exception in correct assignment!")
finally:
    print(comp_zeros)

# Incorrect assignment
try:
    comp_zeros[0].imag = 3
    comp_zeros[1].real = 4
except:
    print("Exception in incorrect assignment!")
finally:
    print(comp_zeros)

Current behavior

I saved above script in test.py.

Script Output

$ python test.py
[0.+0.j 0.+0.j]
[0.+1.j 2.+0.j]
Exception in incorrect assignment!
[0.+1.j 2.+0.j]

Lint Output

$ python -m pylint test.py
************* Module test
test.py:15:4: E1137: 'comp_zeros.imag' does not support item assignment (unsupported-assignment-operation)
test.py:16:4: E1137: 'comp_zeros.real' does not support item assignment (unsupported-assignment-operation)

------------------------------------------------------------------
Your code has been rated at 4.12/10

Expected behavior

I expected E1137 to be appeared in line 24 and 25 (incorrect code).

Lint Output

test.py:24:4: E1137: 'comp_zeros[0].imag' does not support item assignment (unsupported-assignment-operation)
test.py:25:4: E1137: 'comp_zeros[1].real' does not support item assignment (unsupported-assignment-operation)

Versions

pylint 2.4.4
astroid 2.3.3
Python 3.7.5 (tags/v3.7.5:5c02a39a0b, Oct 15 2019, 01:31:54) [MSC v.1916 64 bit (AMD64)]

and

$ pip show numpy
Name: numpy
Version: 1.18.0
... (omitted)
@hippo91
Copy link
Contributor

hippo91 commented Dec 28, 2019

@wldh-g thanks for this report!

@hippo91 hippo91 self-assigned this Dec 28, 2019
@hippo91
Copy link
Contributor

hippo91 commented Feb 5, 2020

@wldh-g there are two problems here: the wrong positive one and the wrong negative one.
For the wrong positive the fix will be quite easy (i have got already a draft) however fixing the wrong negative would necessitate a huge work that is, to my mind, not worthy.

@wldhg
Copy link
Author

wldhg commented Feb 8, 2020

@hippo91 Thanks for your effort! I understand your mind. Does that wrong negative problem is only trouble for this #3322 issue?

@hippo91
Copy link
Contributor

hippo91 commented Feb 14, 2020

@wldh-g i don't have in mind if other issues are also due to this wrong negative problem. I think so but have not more precise information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants