summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Lib/enum.py6
-rw-r--r--Lib/test/test_enum.py8
-rw-r--r--Misc/NEWS.d/next/Library/2023-07-12-04-58-45.gh-issue-106602.dGCcXe.rst1
3 files changed, 15 insertions, 0 deletions
diff --git a/Lib/enum.py b/Lib/enum.py
index 56ebfbd..9114c5c 100644
--- a/Lib/enum.py
+++ b/Lib/enum.py
@@ -1242,6 +1242,12 @@ class Enum(metaclass=EnumType):
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 592deb8..dbdc639 100644
--- a/Lib/test/test_enum.py
+++ b/Lib/test/test_enum.py
@@ -804,9 +804,17 @@ class _MinimalOutputTests:
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 0000000..d9c122f
--- /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`