From f60cedce7c26a35a41e85d2c2144a403a657a348 Mon Sep 17 00:00:00 2001 From: philogicae <38438271+philogicae@users.noreply.github.com> Date: Tue, 20 Feb 2024 13:17:32 +0200 Subject: [PATCH] Revert fix on enum_as_str --- src/aleph/sdk/chains/common.py | 4 ++-- src/aleph/sdk/utils.py | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/aleph/sdk/chains/common.py b/src/aleph/sdk/chains/common.py index 9f6b45f4..3c7e634e 100644 --- a/src/aleph/sdk/chains/common.py +++ b/src/aleph/sdk/chains/common.py @@ -27,9 +27,9 @@ def get_verification_buffer(message: Dict) -> bytes: # Convert Enum values to strings return "\n".join( ( - enum_as_str(message["chain"]), + enum_as_str(message["chain"]) or "", message["sender"], - enum_as_str(message["type"]), + enum_as_str(message["type"]) or "", message["item_hash"], ) ).encode() diff --git a/src/aleph/sdk/utils.py b/src/aleph/sdk/utils.py index f8042898..ab17f44a 100644 --- a/src/aleph/sdk/utils.py +++ b/src/aleph/sdk/utils.py @@ -115,14 +115,14 @@ async def copy_async_readable_to_buffer( buffer.write(chunk) -def enum_as_str(obj: Optional[Union[str, Enum]]) -> str: +def enum_as_str(obj: Optional[Union[str, Enum]]) -> Optional[str]: """Returns the value of an Enum, or the string itself when passing a string. Python 3.11 adds a new formatting of string enums. `str(MyEnum.value)` becomes `MyEnum.value` instead of `value`. """ - if obj is None: - return "" + if not obj: + return None if not isinstance(obj, str): raise TypeError(f"Unsupported enum type: {type(obj)}")