mirror of https://github.com/python/cpython
gh-106602: [Enum] Add __copy__ and __deepcopy__ (GH-106666)
This commit is contained in:
parent
e4b88c1e4a
commit
357e9e9da3
|
@ -1218,6 +1218,12 @@ class Enum(metaclass=EnumType):
|
||||||
def __reduce_ex__(self, proto):
|
def __reduce_ex__(self, proto):
|
||||||
return self.__class__, (self._value_, )
|
return self.__class__, (self._value_, )
|
||||||
|
|
||||||
|
def __deepcopy__(self,memo):
|
||||||
|
return self
|
||||||
|
|
||||||
|
def __copy__(self):
|
||||||
|
return self
|
||||||
|
|
||||||
# enum.property is used to provide access to the `name` and
|
# enum.property is used to provide access to the `name` and
|
||||||
# `value` attributes of enum members while keeping some measure of
|
# `value` attributes of enum members while keeping some measure of
|
||||||
# protection from modification, while still allowing for an enumeration
|
# protection from modification, while still allowing for an enumeration
|
||||||
|
|
|
@ -804,9 +804,17 @@ class _MinimalOutputTests:
|
||||||
TE = self.MainEnum
|
TE = self.MainEnum
|
||||||
copied = copy.copy(TE)
|
copied = copy.copy(TE)
|
||||||
self.assertEqual(copied, TE)
|
self.assertEqual(copied, TE)
|
||||||
|
self.assertIs(copied, TE)
|
||||||
deep = copy.deepcopy(TE)
|
deep = copy.deepcopy(TE)
|
||||||
self.assertEqual(deep, TE)
|
self.assertEqual(deep, TE)
|
||||||
|
self.assertIs(deep, TE)
|
||||||
|
|
||||||
|
def test_copy_member(self):
|
||||||
|
TE = self.MainEnum
|
||||||
|
copied = copy.copy(TE.first)
|
||||||
|
self.assertIs(copied, TE.first)
|
||||||
|
deep = copy.deepcopy(TE.first)
|
||||||
|
self.assertIs(deep, TE.first)
|
||||||
|
|
||||||
class _FlagTests:
|
class _FlagTests:
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Add __copy__ and __deepcopy__ in :mod:`enum`
|
Loading…
Reference in New Issue