diff options
| author | Claudiu Popa <pcmanticore@gmail.com> | 2020-02-10 09:33:35 +0100 |
|---|---|---|
| committer | Claudiu Popa <pcmanticore@gmail.com> | 2020-02-10 09:33:35 +0100 |
| commit | 78e56c64cb016e372a5ae017798ebd7cf83e1f26 (patch) | |
| tree | f4b862b9e2ca5b2efd704545ddfdfb4db1635dd9 | |
| parent | 7dc1d50809a9f1c6b593c41949c28896c6ee0dd7 (diff) | |
| download | astroid-git-78e56c64cb016e372a5ae017798ebd7cf83e1f26.tar.gz | |
Skip non ``Assign`` and ``AnnAssign`` nodes from enum reinterpretation
Closes PyCQA/pylint#3365
| -rw-r--r-- | ChangeLog | 4 | ||||
| -rw-r--r-- | astroid/brain/brain_namedtuple_enum.py | 2 | ||||
| -rw-r--r-- | tests/unittest_brain.py | 15 |
3 files changed, 21 insertions, 0 deletions
@@ -7,6 +7,10 @@ What's New in astroid 2.4.0? Release Date: TBA +* Skip non ``Assign`` and ``AnnAssign`` nodes from enum reinterpretation + + Closes PyCQA/pylint#3365 + * Numpy ``ndarray`` attributes ``imag`` and ``real`` are now inferred as ``ndarray``. Close PyCQA/pylint#3322 diff --git a/astroid/brain/brain_namedtuple_enum.py b/astroid/brain/brain_namedtuple_enum.py index de240671..fee42ad6 100644 --- a/astroid/brain/brain_namedtuple_enum.py +++ b/astroid/brain/brain_namedtuple_enum.py @@ -317,6 +317,8 @@ def infer_enum_class(node): targets = stmt.targets elif isinstance(stmt, nodes.AnnAssign): targets = [stmt.target] + else: + continue inferred_return_value = None if isinstance(stmt, nodes.Assign): diff --git a/tests/unittest_brain.py b/tests/unittest_brain.py index 1a082d12..11b2225d 100644 --- a/tests/unittest_brain.py +++ b/tests/unittest_brain.py @@ -622,6 +622,21 @@ class EnumBrainTest(unittest.TestCase): test = next(enumeration.igetattr("test")) self.assertEqual(test.value, 42) + def test_ignores_with_nodes_from_body_of_enum(self): + code = """ + import enum + + class Error(enum.Enum): + Foo = "foo" + Bar = "bar" + with "error" as err: + pass + """ + node = builder.extract_node(code) + inferred = next(node.infer()) + assert "err" in inferred.locals + assert len(inferred.locals["err"]) == 1 + def test_enum_multiple_base_classes(self): module = builder.parse( """ |
