Skip to content

Commit 5afcfe7

Browse files
authored
Add betterproto.Enum __copy__ and __deepcopy__ implementations
betterproto.Enum is missing __copy__ and __deepcopy__ implementations, which were recently added to enum.Enum, see python/cpython#106602 This fixes the bug where betterproto messages with Enums nested within cannot be copied via copy.deepcopy.
1 parent 126b256 commit 5afcfe7

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/betterproto/enum.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,12 @@ def __delattr__(self, item: Any) -> Never:
156156
f"{self.__class__.__name__} Cannot delete a member's attributes."
157157
)
158158

159+
def __copy__(self):
160+
return self
161+
162+
def __deepcopy__(self, memo):
163+
return self
164+
159165
@classmethod
160166
def try_value(cls, value: int = 0) -> Self:
161167
"""Return the value which corresponds to the value.

0 commit comments

Comments
 (0)