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

Add numpy brain tips for numpy.append #666

Closed
wshanks opened this issue Apr 30, 2019 · 2 comments · Fixed by #739
Closed

Add numpy brain tips for numpy.append #666

wshanks opened this issue Apr 30, 2019 · 2 comments · Fixed by #739
Assignees
Labels
Brain 🧠 Needs a brain tip Enhancement ✨ Improvement to a component

Comments

@wshanks
Copy link

wshanks commented Apr 30, 2019

Steps to reproduce

astroid currently does not account for numpy.append as mentioned in #664. An example of the problem is the following file:

import numpy as np
a = np.append([0], 0)
a = -a

which produces the following errors in pylint:

/tmp/test.py:3:4: E1130: bad operand type for unary -: tuple (invalid-unary-operand-type)
/tmp/test.py:3:4: E1130: bad operand type for unary -: list (invalid-unary-operand-type)

These errors are generated for pylint=1.7.2, astroid=1.5.3 and numpy=1.16.2. The errors are not generated for numpy=1.15.4.

@hippo91
Copy link
Contributor

hippo91 commented May 5, 2019

Thanks for the bug report @willsALMANJ.
The problems comes from the fact that the append function is not correctly inferred as a numpy.ndarray.
I'll try to add a brain for this function ASAP.

@hippo91 hippo91 self-assigned this May 5, 2019
@PCManticore PCManticore added Brain 🧠 Needs a brain tip Enhancement ✨ Improvement to a component labels May 20, 2019
@hippo91
Copy link
Contributor

hippo91 commented Dec 25, 2019

@willsALMANJ just a few words to explain why your issue is not yet solved.
There is no need to add the function append into a numpy brain as this function is defined inside a standard python module inside numpy. The problem arises when astroid tries to infer the result of the call to append. By analyzing the source, astroid is aware that the result of append comes from the call to numpy's concatenate function. This function is defined inside the brain_numpy_core_multiarray astroid module and so should be correctly inferred.
I'am still investigating.

This was referenced Dec 27, 2019
PCManticore pushed a commit that referenced this issue Jan 5, 2020
…current node is an astroid.Name instance

The problem was that astroid could not infer the result of a call to `numpy.append`
because this function calls the `concatenate` function.
This last function is inferred thanks to the `brain_numpy_core_multiarray` module
but only when the corresponding node is an `astroid.Attribute` (for example numpy.concatenate). 
It turns out that in the source of the append function the node that realises the call to concatenate is a `astroid.Name`. Thus the correction proposed here is to register
the concatenate inference tip function in order to apply it, also, to `astroid.Name`.

Close #666
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Brain 🧠 Needs a brain tip Enhancement ✨ Improvement to a component
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants