Skip to content

Commit

Permalink
Add betterproto.Enum __copy__ and __deepcopy__ implementations
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
atomicmac authored Mar 27, 2024
1 parent 126b256 commit 5afcfe7
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/betterproto/enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,12 @@ def __delattr__(self, item: Any) -> Never:
f"{self.__class__.__name__} Cannot delete a member's attributes."
)

def __copy__(self):
return self

def __deepcopy__(self, memo):
return self

@classmethod
def try_value(cls, value: int = 0) -> Self:
"""Return the value which corresponds to the value.
Expand Down

0 comments on commit 5afcfe7

Please sign in to comment.