[Python-checkins] [3.11] gh-106602: [Enum] Add __copy__ and __deepcopy__ (GH-106694)
ethanfurman
webhook-mailer at python.org
Wed Jul 12 18:48:20 EDT 2023
https://github.com/python/cpython/commit/a276ce4505abc72dc3cf3a3a906ad65ef1306203
commit: a276ce4505abc72dc3cf3a3a906ad65ef1306203
branch: 3.11
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: ethanfurman <ethan at stoneleaf.us>
date: 2023-07-12T15:48:16-07:00
summary:
[3.11] gh-106602: [Enum] Add __copy__ and __deepcopy__ (GH-106694)
gh-106602: [Enum] Add __copy__ and __deepcopy__ (GH-106666)
(cherry picked from commit 357e9e9da3929cb9d55ea31896e66f488e44e8f2)
Co-authored-by: Prince Roshan <princekrroshan01 at gmail.com>
files:
A Misc/NEWS.d/next/Library/2023-07-12-04-58-45.gh-issue-106602.dGCcXe.rst
M Lib/enum.py
M Lib/test/test_enum.py
diff --git a/Lib/enum.py b/Lib/enum.py
index 1184b5b13e6d7..1f447c878c1f8 100644
--- a/Lib/enum.py
+++ b/Lib/enum.py
@@ -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
diff --git a/Lib/test/test_enum.py b/Lib/test/test_enum.py
index 442802823e7d0..cc66875bde02a 100644
--- a/Lib/test/test_enum.py
+++ b/Lib/test/test_enum.py
@@ -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:
diff --git a/Misc/NEWS.d/next/Library/2023-07-12-04-58-45.gh-issue-106602.dGCcXe.rst b/Misc/NEWS.d/next/Library/2023-07-12-04-58-45.gh-issue-106602.dGCcXe.rst
new file mode 100644
index 0000000000000..d9c122f1d3c72
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2023-07-12-04-58-45.gh-issue-106602.dGCcXe.rst
@@ -0,0 +1 @@
+Add __copy__ and __deepcopy__ in :mod:`enum`
More information about the Python-checkins
mailing list