-
-
Notifications
You must be signed in to change notification settings - Fork 278
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
Bug pylint 2721 #664
Bug pylint 2721 #664
Conversation
… zeros_like function (pass) and filter tuple for type inferred for a call to zeros_like
…rom types inferred by call to full_like and ones_like
…ay from numpy_core_numerictypes_transform function to infer_numpy_ndarray which is used a inference_tip. Add a _looks_like_numpy_ndarray function. Deletion of the register_transform for linspace function because it is correctly inferred with the inference_tip function for ndarray
…ndarray' and not 'numpy.core.numerictypes.ndarray'
…ure of setitem method. Add of empty_like, ones_like function
…ey are redondant with the one test only ndarray are inferred
…py_* module has its own unittest module
This PR should also prevent infinite recursion for bug pylint-dev/pylint#2865 |
For this file:
I still see:
Should that have been fixed by this PR? |
@willsALMANJ sorry for the delay. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👏 Wow, this is tremendous, thank you so much @hippo91 ! Overall it looks great, but left a couple of comments to be addressed before shipping this, the major one being the use of inference in transform filters. Just looking forward to have a bunch of numpy issues closed at once in pylint's tracker! Thank you again for the great work! 🎉
.gitignore
Outdated
@@ -13,3 +13,6 @@ astroid.egg-info/ | |||
.cache/ | |||
.eggs/ | |||
.pytest_cache/ | |||
.python-version |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hippo91 These should go into your global gitignore, as they are specific to tools you use on your dev environment rather than specific to tools used by the project itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes ! Off-course.
ChangeLog
Outdated
- ``numpy.core.umath`` | ||
- ``numpy.random.mtrand`` | ||
|
||
Close PyCQA/pylint2865 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a nice set of closed issues!
astroid/brain/brain_numpy_utils.py
Outdated
return ( | ||
isinstance(node, astroid.Attribute) | ||
and node.attrname == member_name | ||
and node.expr.inferred()[0].name.startswith("numpy") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hippo91 Unfortunately using inference in the transform filters could have certain recursion error side effects, given that brain
is not fully ready by the time the transform filters are called. Is there any way to prevent having this inference call here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@PCManticore , i changed the way the attribute is meant to be a numpy
member.
I also introduced docstrings and type annotations.
|
||
def subTest(self, msg=None, **params): | ||
try: | ||
# For python versions above 3.5 this should be ok |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❓ Isn't subTest
available from 3.4? If so, we could use it today without the need of subtestMock
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well done @PCManticore . You are totally right this mock is useless now.
I deleted it.
from astroid import builder | ||
|
||
|
||
class SubTestWrapper(unittest.TestCase): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even if we can't subTest
right now (check my previous question on this topic), we should move these definitions into a common test file and use them from there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All occurrences of this mock have been deleted.
…into bug_pylint_2721
Thanks for you review and kind words. |
Hi @hippo91 This should work now if you try again, there was a bug in pylint's master. |
Thanks @PCManticore ! |
@hippo91 Seems to me that the Python 3.8 tests started to fail for both pylint and astroid. We should fix it separate of this PR though. |
Thank you again @hippo91 for all the hard work! 👏 |
You are welcome @PCManticore. Thanks for merging it. |
Steps
Description
This PR is deep rework of the
numpy
brain.The original brain has been split into numerous one. Each
numpy
brain module corresponds toa
numpy
one. There are:brain_numpy_core_fromnumeric
=>numpy.core.fromnumeric
brain_numpy_core_function_base
=>numpy.core.function_base
brain_numpy_core_multiarray
=>numpy.core.multiarray
brain_numpy_core_numeric
=>numpy.core.numeric
brain_core_numerictypes
=>numpy.core.numerictypes
brain_core_umath
=>numpy.core.umath
brain_numpy_random_mtrand
=>numpy.random.mtrand
Last but not least, the
numpy.ndarray
class has its correspondingastroid
's brain (brain_numpy_ndarray
).Each
astroid
's brain has its own associated unit test.The major improvement, besides a clearer organisation, is the fact that each method of the
ndarray
class should now be correctly inferred. Especially those returningndarray
objects.It has been made possible by ensuring that the return type of those methods is inferred as
ndarray
and nothing else. To achieve this, theinference_tip
function has been used.When a
numpy
callable may return two different kinds of objects, for examplebool
orndarray
, the choice to preferndarray
has been made in the correspondingastroid
brain method.There is still work to do, especially correcting the return types of the
brain_numpy_random_mtrand
andbrain_numpy_core_numerictypes
modules. The last one should also be reworked to correct method signature of thegeneric
class.But this PR should strongly improve the
numpy
support forpylint
.Type of Changes
Related Issue
Closes pylint-dev/pylint#2747
Closes pylint-dev/pylint#2721
Closes pylint-dev/pylint#2326
Closes pylint-dev/pylint#2021
Related to pylint-dev/pylint#2767
Related to pylint-dev/pylint#2694
Related to pylint-dev/pylint#2784
Related to pylint-dev/pylint#2759