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

Bug pylint 2721 #664

Merged
merged 49 commits into from
Jun 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
b0ad5a1
Goes back to pass instead of return any for randint function. Declare…
hippo91 Feb 26, 2019
919f938
Removing declaration of zeros_like (pass). Filtering tuple and list f…
hippo91 Feb 26, 2019
0e142fe
Add transforms to define return type of numpy.zeros_like et numpy.lin…
hippo91 Feb 26, 2019
0f7d210
Add a test to ensure that numpy functions calls are infered as numpy …
hippo91 Feb 26, 2019
9714e3b
Merge branch 'master' into bug_pylint_2721
hippo91 Feb 28, 2019
35baf16
Merge branch 'master' into bug_pylint_2721
hippo91 Mar 16, 2019
effaf55
Add a definition for randint function. Move definition of class ndarr…
hippo91 Mar 23, 2019
83aa30f
Correcting inference test. linspace and zeros_like are inferred as '.…
hippo91 Mar 23, 2019
3e7aef9
Merge branch 'master' into bug_pylint_2721
hippo91 Mar 30, 2019
d7c0373
Add of __getitem__ and __setitem__ methods in ndarray. Correct signat…
hippo91 Mar 30, 2019
d6f1fe1
Split the brain_numpy modules in smaller ones for clarity.
hippo91 Mar 31, 2019
81b70ed
Test the unicity of inferred value for function returning ndarray.
hippo91 Apr 2, 2019
c5687bc
Remove test_numpy_function_calls_not_inferred_as_* methods because th…
hippo91 Apr 2, 2019
c5d9205
Finish the split of the numpy brain. Implements all the dunder method…
hippo91 Apr 2, 2019
b7e42aa
Merge branch 'master' into bug_pylint_2721
hippo91 Apr 6, 2019
19f9f27
Finalizing description of numpy.ndarray
hippo91 Apr 6, 2019
86ffb90
Correctiong missing default value
hippo91 Apr 6, 2019
be16e43
Deleting test about __inv__ method which doesn't exists in ndarray
hippo91 Apr 6, 2019
181c83e
Split the unittest_brain_numpy module in parts so that each brain_num…
hippo91 Apr 6, 2019
6be0cda
Changes uninferable return toward correct ones
hippo91 Apr 7, 2019
ecb4fbd
Split the unittest_brain_numpy
hippo91 Apr 7, 2019
0e0edeb
Check that functions return a ndarray
hippo91 Apr 7, 2019
2aba1f9
Split the unittest_brain_numpy module
hippo91 Apr 7, 2019
2308d93
Reformat
hippo91 Apr 7, 2019
27a9d33
Add logspace et geomspace functions
hippo91 Apr 7, 2019
ee0db7f
Typo.
hippo91 Apr 7, 2019
8718254
Add a unittest dedicated to the numpy_core_fromnumeric brain
hippo91 Apr 7, 2019
5869ac5
Merge branch 'master' into bug_pylint_2721
hippo91 Apr 13, 2019
0401d81
Correct prototypes of 3 dunder methods.
hippo91 Apr 20, 2019
cee9012
Refactor in order to test the methods of ndarray
hippo91 Apr 20, 2019
264a547
Rename brain_numpy module and associated unit test module
hippo91 Apr 20, 2019
257c78b
Add the tests concerning ndarray classic methods
hippo91 Apr 20, 2019
bef091d
Add .python-version file and .vscode directory
hippo91 Apr 20, 2019
c1679a6
Add the __init__ method for datetime64and timedelta64
hippo91 Apr 20, 2019
c10320b
Add the function numpy.empty
hippo91 Apr 20, 2019
d05ff50
Add definition for numpy.ones and numpy.zeros functions
hippo91 Apr 20, 2019
42ce258
Reformat for easier new function introduction
hippo91 Apr 20, 2019
585e118
Factorize functions inference system
hippo91 Apr 20, 2019
7d5ae0d
Refactor to make the introduction of new functions easier
hippo91 Apr 21, 2019
4ab338e
Refomat according to black
hippo91 Apr 21, 2019
ee3d323
Corrects the way a numpy member is identified
hippo91 Apr 26, 2019
4ad2fd1
Add the references to pylint bugs corrected
hippo91 Apr 26, 2019
5646dd8
Merge branch 'master' into bug_pylint_2721
hippo91 May 25, 2019
0a81846
Merge branch 'bug_pylint_2721' of https://github.com/hippo91/astroid …
hippo91 May 25, 2019
442dcae
Deleting personal setup
hippo91 May 25, 2019
c2bb4f6
Avoid use of inference engine before it is fully set up. Add docstrings
hippo91 May 25, 2019
f8d12d2
Deleting useless subTest mock for python version prior to 3.4
hippo91 May 25, 2019
40a7ee9
Merge branch 'master' into bug_pylint_2721
hippo91 Jun 1, 2019
f818d1a
Merge branch 'master' into bug_pylint_2721
PCManticore Jun 2, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,25 @@ What's New in astroid 2.3.0?
============================
Release Date: TBA

* Numpy brain support is improved.

Numpy's fundamental type ``numpy.ndarray`` has its own brain : ``brain_numpy_ndarray`` and
each numpy module that necessitates brain action has now its own numpy brain :

- ``numpy.core.numeric``
- ``numpy.core.function_base``
- ``numpy.core.multiarray``
- ``numpy.core.numeric``
- ``numpy.core.numerictypes``
- ``numpy.core.umath``
- ``numpy.random.mtrand``

Close PyCQA/pylint#2865
Close PyCQA/pylint#2747
Close PyCQA/pylint#2721
Close PyCQA/pylint#2326
Close PyCQA/pylint#2021

* Add support for Python 3.8's `NamedExpr` nodes, which is part of assignment expressions.

Close #674
Expand Down
557 changes: 0 additions & 557 deletions astroid/brain/brain_numpy.py

This file was deleted.

23 changes: 23 additions & 0 deletions astroid/brain/brain_numpy_core_fromnumeric.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright (c) 2018-2019 hippo91 <guillaume.peillex@gmail.com>

# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
# For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER


"""Astroid hooks for numpy.core.fromnumeric module."""

import astroid


def numpy_core_fromnumeric_transform():
return astroid.parse(
"""
def sum(a, axis=None, dtype=None, out=None, keepdims=None, initial=None):
return numpy.ndarray([0, 0])
"""
)


astroid.register_module_extender(
astroid.MANAGER, "numpy.core.fromnumeric", numpy_core_fromnumeric_transform
)
29 changes: 29 additions & 0 deletions astroid/brain/brain_numpy_core_function_base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright (c) 2018-2019 hippo91 <guillaume.peillex@gmail.com>

# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
# For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER


"""Astroid hooks for numpy.core.function_base module."""

import functools
import astroid
from brain_numpy_utils import looks_like_numpy_member, infer_numpy_member


METHODS_TO_BE_INFERRED = {
"linspace": """def linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None, axis=0):
return numpy.ndarray([0, 0])""",
"logspace": """def logspace(start, stop, num=50, endpoint=True, base=10.0, dtype=None, axis=0):
return numpy.ndarray([0, 0])""",
"geomspace": """def geomspace(start, stop, num=50, endpoint=True, dtype=None, axis=0):
return numpy.ndarray([0, 0])""",
}

for func_name, func_src in METHODS_TO_BE_INFERRED.items():
inference_function = functools.partial(infer_numpy_member, func_src)
astroid.MANAGER.register_transform(
astroid.Attribute,
astroid.inference_tip(inference_function),
functools.partial(looks_like_numpy_member, func_name),
)
55 changes: 55 additions & 0 deletions astroid/brain/brain_numpy_core_multiarray.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Copyright (c) 2018-2019 hippo91 <guillaume.peillex@gmail.com>

# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
# For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER


"""Astroid hooks for numpy.core.multiarray module."""

import functools
import astroid
from brain_numpy_utils import looks_like_numpy_member, infer_numpy_member


def numpy_core_multiarray_transform():
return astroid.parse(
"""
# different functions defined in multiarray.py
def inner(a, b):
return numpy.ndarray([0, 0])
def vdot(a, b):
return numpy.ndarray([0, 0])
"""
)


astroid.register_module_extender(
astroid.MANAGER, "numpy.core.multiarray", numpy_core_multiarray_transform
)


METHODS_TO_BE_INFERRED = {
"array": """def array(object, dtype=None, copy=True, order='K', subok=False, ndmin=0):
return numpy.ndarray([0, 0])""",
"dot": """def dot(a, b, out=None):
return numpy.ndarray([0, 0])""",
"empty_like": """def empty_like(a, dtype=None, order='K', subok=True):
return numpy.ndarray((0, 0))""",
"concatenate": """def concatenate(arrays, axis=None, out=None):
return numpy.ndarray((0, 0))""",
"where": """def where(condition, x=None, y=None):
return numpy.ndarray([0, 0])""",
"empty": """def empty(shape, dtype=float, order='C'):
return numpy.ndarray([0, 0])""",
"zeros": """def zeros(shape, dtype=float, order='C'):
return numpy.ndarray([0, 0])""",
}

for method_name, function_src in METHODS_TO_BE_INFERRED.items():
inference_function = functools.partial(infer_numpy_member, function_src)
astroid.MANAGER.register_transform(
astroid.Attribute,
astroid.inference_tip(inference_function),
functools.partial(looks_like_numpy_member, method_name),
)
43 changes: 43 additions & 0 deletions astroid/brain/brain_numpy_core_numeric.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Copyright (c) 2018-2019 hippo91 <guillaume.peillex@gmail.com>

# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
# For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER


"""Astroid hooks for numpy.core.numeric module."""

import functools
import astroid
from brain_numpy_utils import looks_like_numpy_member, infer_numpy_member


def numpy_core_numeric_transform():
return astroid.parse(
"""
# different functions defined in numeric.py
import numpy
def zeros_like(a, dtype=None, order='K', subok=True): return numpy.ndarray((0, 0))
def ones_like(a, dtype=None, order='K', subok=True): return numpy.ndarray((0, 0))
def full_like(a, fill_value, dtype=None, order='K', subok=True): return numpy.ndarray((0, 0))
"""
)


astroid.register_module_extender(
astroid.MANAGER, "numpy.core.numeric", numpy_core_numeric_transform
)


METHODS_TO_BE_INFERRED = {
"ones": """def ones(shape, dtype=None, order='C'):
return numpy.ndarray([0, 0])"""
}


for method_name, function_src in METHODS_TO_BE_INFERRED.items():
inference_function = functools.partial(infer_numpy_member, function_src)
astroid.MANAGER.register_transform(
astroid.Attribute,
astroid.inference_tip(inference_function),
functools.partial(looks_like_numpy_member, method_name),
)
Loading