Skip to content

Commit

Permalink
[3.12] gh-106602: [Enum] Add __copy__ and __deepcopy__ (GH-106695)
Browse files Browse the repository at this point in the history
gh-106602: [Enum] Add __copy__ and __deepcopy__ (GH-106666)
(cherry picked from commit 357e9e9)

Co-authored-by: Prince Roshan <princekrroshan01@gmail.com>
  • Loading branch information
miss-islington and Agent-Hellboy committed Jul 12, 2023
1 parent ec7b05a commit 77d9fdf
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Lib/enum.py
Expand Up @@ -1242,6 +1242,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
Expand Down
8 changes: 8 additions & 0 deletions Lib/test/test_enum.py
Expand Up @@ -804,9 +804,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:

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

0 comments on commit 77d9fdf

Please sign in to comment.