From 54cfd7253973fa47915da4bdd1a55ed197d16bab Mon Sep 17 00:00:00 2001 From: Andrew Haigh Date: Sun, 23 May 2021 02:58:48 +1000 Subject: Fix crash on random.sample brain (#993) * Add test of crash on random.sample inference Ref #922 * Fix crash in brain for random.sample Fixes #922. A combination of changes in 79d5a3a7 and 77e205dc meant that the node cloning helper could be given an EvaluatedObject, which doesn't present the same __init__ signature as NodeNG. * Update changelog --- tests/unittest_brain.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'tests') diff --git a/tests/unittest_brain.py b/tests/unittest_brain.py index 0e8c5911..26fad2e3 100644 --- a/tests/unittest_brain.py +++ b/tests/unittest_brain.py @@ -1858,6 +1858,18 @@ class RandomSampleTest(unittest.TestCase): elems = sorted(elem.value for elem in inferred.elts) self.assertEqual(elems, [1, 2]) + def test_no_crash_on_evaluatedobject(self): + node = astroid.extract_node( + """ + from random import sample + class A: pass + sample(list({1: A()}.values()), 1)""" + ) + inferred = next(node.infer()) + assert isinstance(inferred, astroid.List) + assert len(inferred.elts) == 1 + assert isinstance(inferred.elts[0], nodes.Call) + class SubprocessTest(unittest.TestCase): """Test subprocess brain""" -- cgit v1.2.1