Skip to content

Commit

Permalink
Revert fix on enum_as_str
Browse files Browse the repository at this point in the history
  • Loading branch information
philogicae authored and MHHukiewitz committed Feb 20, 2024
1 parent 6a90fe3 commit f60cedc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/aleph/sdk/chains/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions src/aleph/sdk/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)}")

Expand Down

0 comments on commit f60cedc

Please sign in to comment.