summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_enum.py
diff options
context:
space:
mode:
authorEthan Furman <ethan@stoneleaf.us>2022-11-06 01:01:08 (GMT)
committerGitHub <noreply@github.com>2022-11-06 01:01:08 (GMT)
commit8feb7ab77c80968a6de6079299a39b0494b1701b (patch)
tree8e045f6d6400930064f04a5d4a11ab1209a22050 /Lib/test/test_enum.py
parent586b07e1f9f15825e6564df031744fe812b28655 (diff)
downloadcpython-8feb7ab77c80968a6de6079299a39b0494b1701b.zip
cpython-8feb7ab77c80968a6de6079299a39b0494b1701b.tar.gz
cpython-8feb7ab77c80968a6de6079299a39b0494b1701b.tar.bz2
gh-93464: [Enum] fix auto() failure during multiple assignment (GH-99148)
* fix auto() failure during multiple assignment i.e. `ONE = auto(), 'text'` will now have `ONE' with the value of `(1, 'text')`. Before it would have been `(<an auto instance>, 'text')`
Diffstat (limited to 'Lib/test/test_enum.py')
-rw-r--r--Lib/test/test_enum.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/Lib/test/test_enum.py b/Lib/test/test_enum.py
index f50017d..38b1d7c 100644
--- a/Lib/test/test_enum.py
+++ b/Lib/test/test_enum.py
@@ -4116,6 +4116,50 @@ class TestInternals(unittest.TestCase):
third = auto()
self.assertEqual([Dupes.first, Dupes.second, Dupes.third], list(Dupes))
+ def test_multiple_auto_on_line(self):
+ class Huh(Enum):
+ ONE = auto()
+ TWO = auto(), auto()
+ THREE = auto(), auto(), auto()
+ self.assertEqual(Huh.ONE.value, 1)
+ self.assertEqual(Huh.TWO.value, (2, 3))
+ self.assertEqual(Huh.THREE.value, (4, 5, 6))
+ #
+ class Hah(Enum):
+ def __new__(cls, value, abbr=None):
+ member = object.__new__(cls)
+ member._value_ = value
+ member.abbr = abbr or value[:3].lower()
+ return member
+ def _generate_next_value_(name, start, count, last):
+ return name
+ #
+ MONDAY = auto()
+ TUESDAY = auto()
+ WEDNESDAY = auto(), 'WED'
+ THURSDAY = auto(), 'Thu'
+ FRIDAY = auto()
+ self.assertEqual(Hah.MONDAY.value, 'MONDAY')
+ self.assertEqual(Hah.MONDAY.abbr, 'mon')
+ self.assertEqual(Hah.TUESDAY.value, 'TUESDAY')
+ self.assertEqual(Hah.TUESDAY.abbr, 'tue')
+ self.assertEqual(Hah.WEDNESDAY.value, 'WEDNESDAY')
+ self.assertEqual(Hah.WEDNESDAY.abbr, 'WED')
+ self.assertEqual(Hah.THURSDAY.value, 'THURSDAY')
+ self.assertEqual(Hah.THURSDAY.abbr, 'Thu')
+ self.assertEqual(Hah.FRIDAY.value, 'FRIDAY')
+ self.assertEqual(Hah.FRIDAY.abbr, 'fri')
+ #
+ class Huh(Enum):
+ def _generate_next_value_(name, start, count, last):
+ return count+1
+ ONE = auto()
+ TWO = auto(), auto()
+ THREE = auto(), auto(), auto()
+ self.assertEqual(Huh.ONE.value, 1)
+ self.assertEqual(Huh.TWO.value, (2, 2))
+ self.assertEqual(Huh.THREE.value, (3, 3, 3))
+
class TestEnumTypeSubclassing(unittest.TestCase):
pass