summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudiu Popa <pcmanticore@gmail.com>2020-12-26 18:15:33 +0100
committerClaudiu Popa <pcmanticore@gmail.com>2020-12-26 19:12:13 +0100
commit249479692365b93ac0bf7a5765726f5270a1d39e (patch)
treea57ca54363799a15c70d41982d98e67b45ec61eb
parent2f889b7d311fd97d991ec743e3c7f58796613415 (diff)
downloadastroid-git-249479692365b93ac0bf7a5765726f5270a1d39e.tar.gz
Do not crash when encountering starred assignments in enums.
Close #835
-rw-r--r--ChangeLog6
-rw-r--r--astroid/brain/brain_namedtuple_enum.py3
-rw-r--r--tests/unittest_brain.py10
3 files changed, 18 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 4950d1ac..f30157b5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -6,6 +6,8 @@ astroid's ChangeLog
What's New in astroid 2.5.0?
============================
Release Date: TBA
+
+
* Add `python 3.9` support.
* The flat attribute of ``numpy.ndarray`` is now inferred as an ``numpy.ndarray`` itself.
@@ -69,6 +71,10 @@ Release Date: TBA
Close #594
Close #681
+* Do not crash when encountering starred assignments in enums.
+
+ Close #835
+
What's New in astroid 2.4.3?
============================
Release Date: TBA
diff --git a/astroid/brain/brain_namedtuple_enum.py b/astroid/brain/brain_namedtuple_enum.py
index e7f5f17e..932e3dd2 100644
--- a/astroid/brain/brain_namedtuple_enum.py
+++ b/astroid/brain/brain_namedtuple_enum.py
@@ -312,7 +312,6 @@ def infer_enum_class(node):
if any(not isinstance(value, nodes.AssignName) for value in values):
continue
- targets = []
stmt = values[0].statement()
if isinstance(stmt, nodes.Assign):
if isinstance(stmt.targets[0], nodes.Tuple):
@@ -336,6 +335,8 @@ def infer_enum_class(node):
new_targets = []
for target in targets:
+ if isinstance(target, nodes.Starred):
+ continue
# Replace all the assignments with our mocked class.
classdef = dedent(
"""
diff --git a/tests/unittest_brain.py b/tests/unittest_brain.py
index b42fa03f..8b73fa5c 100644
--- a/tests/unittest_brain.py
+++ b/tests/unittest_brain.py
@@ -841,6 +841,16 @@ class EnumBrainTest(unittest.TestCase):
assert inferred_tuple_node.as_string() == "(1, 2)"
assert inferred_list_node.as_string() == "[2, 4]"
+ def test_enum_starred_is_skipped(self):
+ code = """
+ from enum import Enum
+ class ContentType(Enum):
+ TEXT, PHOTO, VIDEO, GIF, YOUTUBE, *_ = [1, 2, 3, 4, 5, 6]
+ ContentType.TEXT #@
+ """
+ node = astroid.extract_node(code)
+ next(node.infer())
+
@unittest.skipUnless(HAS_DATEUTIL, "This test requires the dateutil library.")
class DateutilBrainTest(unittest.TestCase):