Skip to content

Commit a276ce4

Browse files
miss-islingtonAgent-Hellboy
andauthoredJul 12, 2023
[3.11] gh-106602: [Enum] Add __copy__ and __deepcopy__ (GH-106694)
gh-106602: [Enum] Add __copy__ and __deepcopy__ (GH-106666) (cherry picked from commit 357e9e9) Co-authored-by: Prince Roshan <princekrroshan01@gmail.com>
1 parent eac0616 commit a276ce4

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed
 

‎Lib/enum.py

+6
Original file line numberDiff line numberDiff line change
@@ -1227,6 +1227,12 @@ def __hash__(self):
12271227
def __reduce_ex__(self, proto):
12281228
return self.__class__, (self._value_, )
12291229

1230+
def __deepcopy__(self,memo):
1231+
return self
1232+
1233+
def __copy__(self):
1234+
return self
1235+
12301236
# enum.property is used to provide access to the `name` and
12311237
# `value` attributes of enum members while keeping some measure of
12321238
# protection from modification, while still allowing for an enumeration

‎Lib/test/test_enum.py

+8
Original file line numberDiff line numberDiff line change
@@ -775,9 +775,17 @@ def test_copy(self):
775775
TE = self.MainEnum
776776
copied = copy.copy(TE)
777777
self.assertEqual(copied, TE)
778+
self.assertIs(copied, TE)
778779
deep = copy.deepcopy(TE)
779780
self.assertEqual(deep, TE)
781+
self.assertIs(deep, TE)
780782

783+
def test_copy_member(self):
784+
TE = self.MainEnum
785+
copied = copy.copy(TE.first)
786+
self.assertIs(copied, TE.first)
787+
deep = copy.deepcopy(TE.first)
788+
self.assertIs(deep, TE.first)
781789

782790
class _FlagTests:
783791

Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add __copy__ and __deepcopy__ in :mod:`enum`

0 commit comments

Comments
 (0)