From bb7fe8d661353b7aed137c9345b91bce721041e0 Mon Sep 17 00:00:00 2001 From: hippo91 Date: Fri, 27 Dec 2019 11:00:54 +0100 Subject: Adds two missing ufunc instances (add and multiply) --- astroid/brain/brain_numpy_core_umath.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/astroid/brain/brain_numpy_core_umath.py b/astroid/brain/brain_numpy_core_umath.py index 9e03bb9e..1a1788d2 100644 --- a/astroid/brain/brain_numpy_core_umath.py +++ b/astroid/brain/brain_numpy_core_umath.py @@ -101,6 +101,7 @@ def numpy_core_umath_transform(): trunc = FakeUfuncOneArg() # Two args functions with optional kwargs + add = FakeUfuncTwoArgs() bitwise_and = FakeUfuncTwoArgs() bitwise_or = FakeUfuncTwoArgs() bitwise_xor = FakeUfuncTwoArgs() @@ -123,6 +124,7 @@ def numpy_core_umath_transform(): logical_xor = FakeUfuncTwoArgs() maximum = FakeUfuncTwoArgs() minimum = FakeUfuncTwoArgs() + multiply = FakeUfuncTwoArgs() nextafter = FakeUfuncTwoArgs() not_equal = FakeUfuncTwoArgs() power = FakeUfuncTwoArgs() -- cgit v1.2.1 From 0cd44c7616a4018e26cda48d65b2fe2781392ed1 Mon Sep 17 00:00:00 2001 From: hippo91 Date: Fri, 27 Dec 2019 12:03:17 +0100 Subject: Add the test of functions add and multiply --- tests/unittest_brain_numpy_core_umath.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/unittest_brain_numpy_core_umath.py b/tests/unittest_brain_numpy_core_umath.py index 51b696f6..3307a8c1 100644 --- a/tests/unittest_brain_numpy_core_umath.py +++ b/tests/unittest_brain_numpy_core_umath.py @@ -60,6 +60,7 @@ class NumpyBrainCoreUmathTest(unittest.TestCase): ) two_args_ufunc = ( + "add", "bitwise_and", "bitwise_or", "bitwise_xor", @@ -82,6 +83,7 @@ class NumpyBrainCoreUmathTest(unittest.TestCase): "logical_xor", "maximum", "minimum", + "multiply", "nextafter", "not_equal", "power", -- cgit v1.2.1 From 4fc45c581523e4883937e1b7a5314e434e8f3125 Mon Sep 17 00:00:00 2001 From: hippo91 Date: Mon, 30 Dec 2019 13:40:42 +0100 Subject: Insures that numpy functions returning arrays are inferred only as array and not [array, Uninferable] because it could lead to false negatives. --- tests/unittest_brain_numpy_core_umath.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/unittest_brain_numpy_core_umath.py b/tests/unittest_brain_numpy_core_umath.py index 3307a8c1..2a78a1eb 100644 --- a/tests/unittest_brain_numpy_core_umath.py +++ b/tests/unittest_brain_numpy_core_umath.py @@ -216,11 +216,9 @@ class NumpyBrainCoreUmathTest(unittest.TestCase): with self.subTest(typ=func_): inferred_values = list(self._inferred_numpy_func_call(func_)) self.assertTrue( - len(inferred_values) == 1 - or len(inferred_values) == 2 - and inferred_values[-1].pytype() is util.Uninferable, + len(inferred_values) == 1, msg="Too much inferred values ({}) for {:s}".format( - inferred_values[-1].pytype(), func_ + inferred_values, func_ ), ) self.assertTrue( -- cgit v1.2.1 From cc3bfc5dc94062a582b7b3226598f09d7ec7044e Mon Sep 17 00:00:00 2001 From: hippo91 Date: Mon, 30 Dec 2019 13:42:18 +0100 Subject: Turns the context.path from a set to a dict which values are the number of times the node has been visited. The push method return True depending on a condition of the number of visits. --- astroid/context.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/astroid/context.py b/astroid/context.py index 70a92088..113cac6b 100644 --- a/astroid/context.py +++ b/astroid/context.py @@ -28,8 +28,10 @@ class InferenceContext: "extra_context", ) + maximum_path_visit = 3 + def __init__(self, path=None, inferred=None): - self.path = path or set() + self.path = path or dict() """ :type: set(tuple(NodeNG, optional(str))) @@ -86,10 +88,10 @@ class InferenceContext: Allows one to see if the given node has already been looked at for this inference context""" name = self.lookupname - if (node, name) in self.path: + if self.path.get((node, name), 0) >= self.maximum_path_visit: return True - self.path.add((node, name)) + self.path[(node, name)] = self.path.setdefault((node, name), 0) + 1 return False def clone(self): @@ -118,7 +120,7 @@ class InferenceContext: @contextlib.contextmanager def restore_path(self): - path = set(self.path) + path = dict(self.path) yield self.path = path -- cgit v1.2.1 From be78cd4a531aeb66f2c2292fb717f8c5db6e2a47 Mon Sep 17 00:00:00 2001 From: hippo91 Date: Mon, 30 Dec 2019 13:44:30 +0100 Subject: Updates two tests that deal with the number of visits and the context.path --- tests/unittest_inference.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/unittest_inference.py b/tests/unittest_inference.py index a5ed96b1..b541eb28 100644 --- a/tests/unittest_inference.py +++ b/tests/unittest_inference.py @@ -1313,7 +1313,7 @@ class InferenceTest(resources.SysPathSetup, unittest.TestCase): result = node.inferred() assert len(result) == 2 assert isinstance(result[0], nodes.Dict) - assert result[1] is util.Uninferable + assert isinstance(result[1], nodes.Dict) def test_python25_no_relative_import(self): ast = resources.build_file("data/package/absimport.py") @@ -3666,7 +3666,8 @@ class InferenceTest(resources.SysPathSetup, unittest.TestCase): flow = AttributeDict() flow['app'] = AttributeDict() flow['app']['config'] = AttributeDict() - flow['app']['config']['doffing'] = AttributeDict() #@ + flow['app']['config']['doffing'] = AttributeDict() + flow['app']['config']['doffing']['thinkto'] = AttributeDict() #@ """ ) self.assertIsNone(helpers.safe_infer(ast_node.targets[0])) -- cgit v1.2.1 From 06c98d3c3cff7670c4330882ca6acd4a505a6903 Mon Sep 17 00:00:00 2001 From: hippo91 Date: Mon, 30 Dec 2019 14:12:26 +0100 Subject: Added an entry --- ChangeLog | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ChangeLog b/ChangeLog index b612aee0..d66b3710 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,11 @@ What's New in astroid 2.4.0? ============================ Release Date: TBA +* The ``context.path`` is now a ``dict`` and the ``context.push`` method + returns ``True`` if the node has been visited a certain amount of times. + + Close #669 + * Added some functions of the ``numpy.core.multiarray`` module Close PyCQA/pylint#3208 -- cgit v1.2.1 From e3e2d8a8e9fc3b1bdc0d7e8471313ce18f25d613 Mon Sep 17 00:00:00 2001 From: hippo91 Date: Mon, 30 Dec 2019 14:33:55 +0100 Subject: Corrects the use of numpy.multiply function --- tests/unittest_regrtest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unittest_regrtest.py b/tests/unittest_regrtest.py index 8224494b..91fa8f16 100644 --- a/tests/unittest_regrtest.py +++ b/tests/unittest_regrtest.py @@ -92,7 +92,7 @@ class NonRegressionTests(resources.AstroidCacheSetupMixin, unittest.TestCase): data = """ from numpy import multiply -multiply(1, 2, 3) +multiply([1, 2], [3, 4]) """ astroid = builder.string_build(data, __name__, __file__) callfunc = astroid.body[1].value.func -- cgit v1.2.1