Closed bersbersbers closed 4 years ago
Hi @bersbersbers thanks for reporting the issue.
Same problem as reported by @bersbersbers in #2767 occurs when using np.zeros_like(...)
.
Also, use of np.logical_or(..., ...)
generates an assignment-from-no-return
pylint error.
Neither of these errors were generated by earlier versions of pylint.
cc @PCManticore
@martinholmer @bersbersbers thank for the report. In fact it's very close to #2746 #2694 #2784.
In early times of pylint
the brain used to deal with numpy
was quite simple. We, then, had a lot of no-member
false positives. They were due to the fact that some numpy
modules are written in c language, especially those at the core of numpy
and thus astroid
(the pylint
inference engine) can not infer any object defined in those modules.
To correct this, i wrote python ghosts of those numpy
c modules in order astroid
/pylint
to deal with them correctly (PyCQA/astroid#567 PyCQA/astroid#486). It implied studying numpy
deeply and wrote a python ghost
for every function/class that numpy
defines in c language. At this point almost all classes or functions are defined and thus almost all no-member
false positives should have gone away. However the call to such functions/methods cannot yet be inferred. That's why you are facing such problems.
I'am currently working on an improvment of astroid
s numpy
brain. It's quite a hard work and have not so much time to spent on it but i hope it will be finished quite soon.
Sorry for that long message but i wanted to explain why you and other numpy
+ pylint
users are facing such problems.
@hippo91 said in issue #2767:
Sorry for that long message but I wanted to explain why you and other numpy + pylint users are facing such problems.
Thanks for the helpful explanation, and thanks especially for all your ongoing work on this problem.
not sure if this helps:
but I found that the following throwed a unsupported-assignment-operation
my_array = np.zeros_like(another_array)
condition_array = _np.where(_np.less(different_array, my_array))
my_array[condition_array] = values
that could be solved by calling np.zeros(another_array.shape)
instead of zeros_like
@jordyjwilliams said in issue #2767:
I found that the following throwed a
unsupported-assignment-operation
pylint warning:my_array = np.zeros_like(another_array) condition_array = _np.where(_np.less(different_array, my_array)) my_array[condition_array] = values
that could be solved by calling
np.zeros(another_array.shape)
instead ofnp.zeros_like(another_array)
.
Thanks for the useful tip!
@martinholmer , @jordyjwilliams
The problem you were facing should have disappeared with, at least, the 2.3
version of astroid
.
That's why i'm closing this issue.
Feel free to reopen it if necessary.
I am also experiencing this problem. The example code:
"""X"""
import numpy as np
X = np.empty_like([1])
X[:] = 2
works as expected, but the almost identical code:
"""X"""
from numpy import empty_like
X = empty_like([1])
X[:] = 2
raises the error:
************* Module bug
bug.py:5:0: E1137: 'X' does not support item assignment (unsupported-assignment-operation)
pylint 3.0.3
astroid 3.0.2
Python 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0]
@EmilyBourne you should open a new issue, this is going to get lost otherwise
Steps to reproduce
pylint this file:
Current behavior
Expected behavior
No error, code runs fine in
python bug.py
pylint --version output