Skip to content

Commit

Permalink
Append methods from the inherited class to the new enum class
Browse files Browse the repository at this point in the history
  • Loading branch information
albireox committed Jan 23, 2024
1 parent 1c1e8e3 commit 70eaf58
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/lvmopstools/actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,18 @@ def wrapper(added_enum):
joined[item.name] = item.value
for item in added_enum:
joined[item.name] = item.value
return enum.Enum(added_enum.__name__, joined)

new_enum_class = enum.Enum(added_enum.__name__, joined)

# Add methods from the inherited class.
for attr in inherited_enum.__dict__:
if attr.startswith("__"):
continue
if hasattr(new_enum_class, attr):
continue
setattr(new_enum_class, attr, getattr(inherited_enum, attr))

return new_enum_class

return wrapper

Expand Down
2 changes: 2 additions & 0 deletions tests/test_actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class ExtraErrorCodes(enum.Enum):
assert hasattr(ExtraErrorCodes, "SOME_FAILURE_MODE")
assert hasattr(ExtraErrorCodes, "UNKNOWN")

assert hasattr(ExtraErrorCodes, "get_error_code")


def test_verify_error_codes_fails():
with pytest.raises(ValueError):
Expand Down

0 comments on commit 70eaf58

Please sign in to comment.