From 5afcfe7a99da1507c923dd9aea32acb6ffa9a371 Mon Sep 17 00:00:00 2001 From: atomicmac <156139337+atomicmac@users.noreply.github.com> Date: Wed, 27 Mar 2024 14:35:52 -0700 Subject: [PATCH] Add betterproto.Enum __copy__ and __deepcopy__ implementations betterproto.Enum is missing __copy__ and __deepcopy__ implementations, which were recently added to enum.Enum, see https://github.com/python/cpython/issues/106602 This fixes the bug where betterproto messages with Enums nested within cannot be copied via copy.deepcopy. --- src/betterproto/enum.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/betterproto/enum.py b/src/betterproto/enum.py index 529832251..f05808c2a 100644 --- a/src/betterproto/enum.py +++ b/src/betterproto/enum.py @@ -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.