mirror of
https://github.com/python/cpython.git
synced 2025-08-29 13:15:11 +00:00
gh-100098: [Enum] insist on actual tuples, no subclasses, for auto (GH-100099)
When checking for auto() instances, only top-level usage is supported, which means either alone or as part of a regular tuple. Other containers, such as lists, dicts, or namedtuples, will not have auto() transformed into a value.
This commit is contained in:
parent
cce8362960
commit
ded02ca54d
3 changed files with 17 additions and 1 deletions
|
@ -2841,6 +2841,19 @@ class TestSpecial(unittest.TestCase):
|
|||
self.assertEqual(deep, flags)
|
||||
self.assertEqual(copied.value, 1 | 2 | 8)
|
||||
|
||||
def test_namedtuple_as_value(self):
|
||||
from collections import namedtuple
|
||||
TTuple = namedtuple('TTuple', 'id a blist')
|
||||
class NTEnum(Enum):
|
||||
NONE = TTuple(0, 0, [])
|
||||
A = TTuple(1, 2, [4])
|
||||
B = TTuple(2, 4, [0, 1, 2])
|
||||
self.assertEqual(repr(NTEnum.NONE), "<NTEnum.NONE: TTuple(id=0, a=0, blist=[])>")
|
||||
self.assertEqual(NTEnum.NONE.value, TTuple(id=0, a=0, blist=[]))
|
||||
self.assertEqual(
|
||||
[x.value for x in NTEnum],
|
||||
[TTuple(id=0, a=0, blist=[]), TTuple(id=1, a=2, blist=[4]), TTuple(id=2, a=4, blist=[0, 1, 2])],
|
||||
)
|
||||
|
||||
class TestOrder(unittest.TestCase):
|
||||
"test usage of the `_order_` attribute"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue