[3.11] gh-106602: [Enum] Add __copy__ and __deepcopy__ (GH-106694)

gh-106602: [Enum] Add __copy__ and __deepcopy__ (GH-106666)
(cherry picked from commit 357e9e9da3)

Co-authored-by: Prince Roshan <princekrroshan01@gmail.com>
This commit is contained in:
Miss Islington (bot) 2023-07-12 15:48:16 -07:00 committed by GitHub
parent eac0616df9
commit a276ce4505
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 0 deletions

View file

@ -1227,6 +1227,12 @@ def __hash__(self):
def __reduce_ex__(self, proto):
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
# `value` attributes of enum members while keeping some measure of
# protection from modification, while still allowing for an enumeration

View file

@ -775,9 +775,17 @@ def test_copy(self):
TE = self.MainEnum
copied = copy.copy(TE)
self.assertEqual(copied, TE)
self.assertIs(copied, TE)
deep = copy.deepcopy(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:

View file

@ -0,0 +1 @@
Add __copy__ and __deepcopy__ in :mod:`enum`