diff options
| author | Andrew Haigh <hello@nelf.in> | 2021-05-23 02:58:48 +1000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-05-22 18:58:48 +0200 |
| commit | 54cfd7253973fa47915da4bdd1a55ed197d16bab (patch) | |
| tree | 943122f9579565d1496711d152f7225b0f728e41 /tests | |
| parent | 01f9e2439513a83899b88b1053ca90f81ab49903 (diff) | |
| download | astroid-git-54cfd7253973fa47915da4bdd1a55ed197d16bab.tar.gz | |
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
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/unittest_brain.py | 12 |
1 files changed, 12 insertions, 0 deletions
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""" |
