diff --git a/.gitignore b/.gitignore index 66d64d3e5d..4b0ef30852 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ astroid.egg-info/ .cache/ .eggs/ .pytest_cache/ +.mypy_cache/ \ No newline at end of file diff --git a/ChangeLog b/ChangeLog index 5145203f0d..f426493560 100644 --- a/ChangeLog +++ b/ChangeLog @@ -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 a9bc73b4b2..d996754a87 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 93dd3d3123..87947ec68d 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 defce47dba..d5a96cc824 100644 --- a/tests/unittest_brain_numpy_ndarray.py +++ b/tests/unittest_brain_numpy_ndarray.py @@ -154,7 +154,7 @@ def test_numpy_ndarray_attribute_inferred_as_ndarray(self): 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(