Skip to content

Commit df1ba91

Browse files
atomicmacGobot1234
andauthored
Add betterproto.Enum __copy__ and __deepcopy__ implementations (#566)
* 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. * Type hint on Enum.__copy__ Co-authored-by: James Hilton-Balfe <[email protected]> * Type hint on Enum.__deepcopy__ Co-authored-by: James Hilton-Balfe <[email protected]> --------- Co-authored-by: James Hilton-Balfe <[email protected]>
1 parent 126b256 commit df1ba91

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) -> Self:
160+
return self
161+
162+
def __deepcopy__(self, memo: Any) -> Self:
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)