mirror of
https://github.com/python/cpython.git
synced 2025-08-30 21:48:47 +00:00
issue23673
add private method to enum to support replacing global constants with Enum members: - search for candidate constants via supplied filter - create new enum class and members - insert enum class and replace constants with members via supplied module name - replace __reduce_ex__ with function that returns member name, so previous Python versions can unpickle modify IntEnum classes to use new method
This commit is contained in:
parent
d833779cea
commit
482fe0477e
4 changed files with 47 additions and 8 deletions
|
@ -581,6 +581,14 @@ class TestEnum(unittest.TestCase):
|
|||
test_pickle_dump_load(self.assertIs, self.NestedEnum.twigs,
|
||||
protocol=(4, HIGHEST_PROTOCOL))
|
||||
|
||||
def test_pickle_by_name(self):
|
||||
class ReplaceGlobalInt(IntEnum):
|
||||
ONE = 1
|
||||
TWO = 2
|
||||
ReplaceGlobalInt.__reduce_ex__ = enum._reduce_ex_by_name
|
||||
for proto in range(HIGHEST_PROTOCOL):
|
||||
self.assertEqual(ReplaceGlobalInt.TWO.__reduce_ex__(proto), 'TWO')
|
||||
|
||||
def test_exploding_pickle(self):
|
||||
BadPickle = Enum(
|
||||
'BadPickle', 'dill sweet bread-n-butter', module=__name__)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue