diff options
-rw-r--r-- | ChangeLog | 2 | ||||
-rw-r--r-- | astroid/brain/pynumpy.py | 46 | ||||
-rw-r--r-- | astroid/tests/unittest_brain.py | 19 |
3 files changed, 67 insertions, 0 deletions
@@ -310,6 +310,8 @@ Change log for the astroid package (used to be astng) leads to a class creationg, not to an instance creation. * Understand the `slice` builtin. Closes issue #184. + + * Add brain tips for numpy.core, which should fix Pylint's #453. diff --git a/astroid/brain/pynumpy.py b/astroid/brain/pynumpy.py new file mode 100644 index 0000000..cb43339 --- /dev/null +++ b/astroid/brain/pynumpy.py @@ -0,0 +1,46 @@ +# copyright 2003-2015 LOGILAB S.A. (Paris, FRANCE), all rights reserved. +# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr +# +# This file is part of astroid. +# +# astroid is free software: you can redistribute it and/or modify it under +# the terms of the GNU Lesser General Public License as published by the Free +# Software Foundation, either version 2.1 of the License, or (at your option) any +# later version. +# +# astroid is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more +# details. +# +# You should have received a copy of the GNU Lesser General Public License along +# with astroid. If not, see <http://www.gnu.org/licenses/>. + +"""Astroid hooks for numpy.""" + +import astroid + + +# TODO(cpopa): drop when understanding augmented assignments + +def numpy_core_transform(): + module = astroid.parse(''' + from numpy.core import numeric + from numpy.core import fromnumeric + from numpy.core import defchararray + from numpy.core import records + from numpy.core import function_base + from numpy.core import machar + from numpy.core import getlimits + from numpy.core import shape_base + __all__ = (['char', 'rec', 'memmap', 'chararray'] + numeric.__all__ + + fromnumeric.__all__ + + records.__all__ + + function_base.__all__ + + machar.__all__ + + getlimits.__all__ + + shape_base.__all__) + ''') + return module + +astroid.register_module_extender(astroid.MANAGER, 'numpy.core', numpy_core_transform) diff --git a/astroid/tests/unittest_brain.py b/astroid/tests/unittest_brain.py index 7a6d8d2..510b4c0 100644 --- a/astroid/tests/unittest_brain.py +++ b/astroid/tests/unittest_brain.py @@ -53,6 +53,13 @@ try: except ImportError: HAS_DATEUTIL = False +try: + import numpy # pylint: disable=unused-import + HAS_NUMPY = True +except ImportError: + HAS_NUMPY = False + + class HashlibTest(unittest.TestCase): def test_hashlib(self): """Tests that brain extensions for hashlib work.""" @@ -419,5 +426,17 @@ class DateutilBrainTest(unittest.TestCase): self.assertEqual(d_type.qname(), "datetime.datetime") +@unittest.skipUnless(HAS_NUMPY, "This test requires the numpy library.") +class NumpyBrainTest(unittest.TestCase): + + def test_numpy(self): + node = test_utils.extract_node(''' + import numpy + numpy.ones #@ + ''') + inferred = next(node.infer()) + self.assertIsInstance(inferred, nodes.Function) + + if __name__ == '__main__': unittest.main() |