diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2022-06-17 03:56:20 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-17 03:56:20 (GMT) |
commit | 3fbf5c6427c260eab41c37f6eb7f66b79ab4ea88 (patch) | |
tree | 19afb4bcfe12aef6fb39c52496479d87772a3c0e /Lib/test/test_enum.py | |
parent | 74561095d906c2ca8ca8f41f22cb23a9e5b58954 (diff) | |
download | cpython-3fbf5c6427c260eab41c37f6eb7f66b79ab4ea88.zip cpython-3fbf5c6427c260eab41c37f6eb7f66b79ab4ea88.tar.gz cpython-3fbf5c6427c260eab41c37f6eb7f66b79ab4ea88.tar.bz2 |
gh-93820: Fix copy() regression in enum.Flag (GH-93876) (#93886)
GH-26658 introduced a regression in copy / pickle protocol for combined
`enum.Flag`s. `copy.copy(re.A | re.I)` would fail with
`AttributeError: ASCII|IGNORECASE`.
`enum.Flag` now has a `__reduce_ex__()` method that reduces flags by
combined value, not by combined name.
(cherry picked from commit 05b32c1c796d6c80479756ae898f488eac5f4f71)
Co-authored-by: Christian Heimes <christian@python.org>
Co-authored-by: Christian Heimes <christian@python.org>
Diffstat (limited to 'Lib/test/test_enum.py')
-rw-r--r-- | Lib/test/test_enum.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/Lib/test/test_enum.py b/Lib/test/test_enum.py index 56cebfe..b44c566 100644 --- a/Lib/test/test_enum.py +++ b/Lib/test/test_enum.py @@ -1,3 +1,4 @@ +import copy import enum import doctest import inspect @@ -732,6 +733,13 @@ class _MinimalOutputTests: self.assertFormatIsValue('{:5.2}', TE.third) self.assertFormatIsValue('{:f}', TE.third) + def test_copy(self): + TE = self.MainEnum + copied = copy.copy(TE) + self.assertEqual(copied, TE) + deep = copy.deepcopy(TE) + self.assertEqual(deep, TE) + class _FlagTests: @@ -2652,6 +2660,26 @@ class TestSpecial(unittest.TestCase): self.assertTrue(isinstance(MyIntFlag.ONE | MyIntFlag.TWO, MyIntFlag), MyIntFlag.ONE | MyIntFlag.TWO) self.assertTrue(isinstance(MyIntFlag.ONE | 2, MyIntFlag)) + def test_int_flags_copy(self): + class MyIntFlag(IntFlag): + ONE = 1 + TWO = 2 + FOUR = 4 + + flags = MyIntFlag.ONE | MyIntFlag.TWO + copied = copy.copy(flags) + deep = copy.deepcopy(flags) + self.assertEqual(copied, flags) + self.assertEqual(deep, flags) + + flags = MyIntFlag.ONE | MyIntFlag.TWO | 8 + copied = copy.copy(flags) + deep = copy.deepcopy(flags) + self.assertEqual(copied, flags) + self.assertEqual(deep, flags) + self.assertEqual(copied.value, 1 | 2 | 8) + + class TestOrder(unittest.TestCase): "test usage of the `_order_` attribute" |