diff options
| author | Claudiu Popa <pcmanticore@gmail.com> | 2020-05-01 08:22:28 +0200 |
|---|---|---|
| committer | Claudiu Popa <pcmanticore@gmail.com> | 2020-05-01 08:29:21 +0200 |
| commit | e40ac59e470d7166369732f84b8ae7ce9164b0a3 (patch) | |
| tree | d7d8bdd627f2321d21b22de88441415d644ac5b5 /tests | |
| parent | b02f70a25ca89a3a43686b872831660d49bff84e (diff) | |
| download | astroid-git-e40ac59e470d7166369732f84b8ae7ce9164b0a3.tar.gz | |
Do not crash with SyntaxError when parsing namedtuples with invalid label
Close PyCQA/pylint#3549
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 cb11c4cf..0a833664 100644 --- a/tests/unittest_brain.py +++ b/tests/unittest_brain.py @@ -331,6 +331,18 @@ class NamedTupleTest(unittest.TestCase): self.assertIsInstance(inferred.bases[0], astroid.Name) self.assertEqual(inferred.bases[0].name, "tuple") + def test_invalid_label_does_not_crash_inference(self): + code = """ + import collections + a = collections.namedtuple( 'a', ['b c'] ) + a + """ + node = builder.extract_node(code) + inferred = next(node.infer()) + assert isinstance(inferred, astroid.ClassDef) + assert "b" not in inferred.locals + assert "c" not in inferred.locals + class DefaultDictTest(unittest.TestCase): def test_1(self): |
