diff options
author | hippo91 <guillaume.peillex@gmail.com> | 2020-09-14 22:19:05 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-14 22:19:05 +0200 |
commit | 1d14e985baf8847be60b81b7f6140e8606fd862a (patch) | |
tree | ae784d475070530f94b287b525342d8a907008f3 | |
parent | 290df4864420b7322aa5990c2f557a3740c03131 (diff) | |
download | astroid-git-1d14e985baf8847be60b81b7f6140e8606fd862a.tar.gz |
Adds ndarray as rtype for T attribute.
Closes PyCQA/pylint#3387
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | astroid/brain/brain_numpy_core_numerictypes.py | 2 | ||||
-rw-r--r-- | astroid/brain/brain_numpy_ndarray.py | 2 | ||||
-rw-r--r-- | tests/unittest_brain_numpy_ndarray.py | 2 |
5 files changed, 8 insertions, 3 deletions
@@ -13,3 +13,4 @@ astroid.egg-info/ .cache/ .eggs/ .pytest_cache/ +.mypy_cache/
\ No newline at end of file @@ -18,6 +18,10 @@ Release Date: TBA * Added a brain for ``hypothesis.strategies.composite`` +* The transpose of a ``numpy.ndarray`` is also a ``numpy.ndarray`` + + Fixes PyCQA/pylint#3387 + * Added a brain for ``sqlalchemy.orm.session`` * Separate string and bytes classes patching diff --git a/astroid/brain/brain_numpy_core_numerictypes.py b/astroid/brain/brain_numpy_core_numerictypes.py index a9bc73b4..d996754a 100644 --- a/astroid/brain/brain_numpy_core_numerictypes.py +++ b/astroid/brain/brain_numpy_core_numerictypes.py @@ -20,7 +20,7 @@ def numpy_core_numerictypes_transform(): # different types defined in numerictypes.py class generic(object): def __init__(self, value): - self.T = None + self.T = np.ndarray([0, 0]) self.base = None self.data = None self.dtype = None diff --git a/astroid/brain/brain_numpy_ndarray.py b/astroid/brain/brain_numpy_ndarray.py index 93dd3d31..87947ec6 100644 --- a/astroid/brain/brain_numpy_ndarray.py +++ b/astroid/brain/brain_numpy_ndarray.py @@ -17,7 +17,7 @@ def infer_numpy_ndarray(node, context=None): class ndarray(object): def __init__(self, shape, dtype=float, buffer=None, offset=0, strides=None, order=None): - self.T = None + self.T = numpy.ndarray([0, 0]) self.base = None self.ctypes = None self.data = None diff --git a/tests/unittest_brain_numpy_ndarray.py b/tests/unittest_brain_numpy_ndarray.py index defce47d..d5a96cc8 100644 --- a/tests/unittest_brain_numpy_ndarray.py +++ b/tests/unittest_brain_numpy_ndarray.py @@ -154,7 +154,7 @@ class NumpyBrainNdarrayTest(unittest.TestCase): Test that some numpy ndarray attributes are inferred as numpy.ndarray """ licit_array_types = ".ndarray" - for attr_ in ("real", "imag"): + for attr_ in ("real", "imag", "shape", "T"): with self.subTest(typ=attr_): inferred_values = list(self._inferred_ndarray_attribute(attr_)) self.assertTrue( |