8000 [3.11] gh-106602: [Enum] Add __copy__ and __deepcopy__ (GH-106666) by miss-islington · Pull Request #106694 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
8000 Failed to load files.
Loading
Diff view
Diff view
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
Agent-Hellboy authored and miss-islington committed Jul 12, 2023
commit 6108571577f0dbff249ccd970a25a4b50f155f85
6 changes: 6 additions & 0 deletions Lib/enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
8000 Expand Down
8 changes: 8 additions & 0 deletions Lib/test/test_enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add __copy__ and __deepcopy__ in :mod:`enum`
0