Skip to content

Commit

Permalink
tidy AddonOperation
Browse files Browse the repository at this point in the history
  • Loading branch information
aaxelb committed Feb 8, 2024
1 parent b442bce commit c8b51f5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
9 changes: 6 additions & 3 deletions addon_toolkit/operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,14 @@ class _UnboundAddonOperation:

def __set_name__(self, cls, name):
AddonOperation._register_operation(self, cls, name)
# replace this AddonOperation with the original function
# replace this _UnboundAddonOperation with the original function
setattr(cls, name, self.operation_fn)


@dataclasses.dataclass(frozen=True)
class AddonOperation(_UnboundAddonOperation):
class AddonOperation:
operation_type: AddonOperationType
capability: enum.Enum
declaration_cls: type[AddonInterface]
method_name: str

Expand All @@ -81,7 +83,8 @@ def _register_operation(
method_name: str,
):
_operation = cls(
**dataclasses.asdict(unbound_operation),
operation_type=unbound_operation.operation_type,
capability=unbound_operation.capability,
declaration_cls=declaration_cls,
method_name=method_name,
)
Expand Down
3 changes: 0 additions & 3 deletions addon_toolkit/tests/test_addon_category.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,21 +62,18 @@ def test_operation_list(self):
_my_cap = self.my_addon_category.capabilities
_my_interface_cls = self.my_addon_category.base_interface
_expected_get_op = AddonOperation(
operation_fn=_my_interface_cls.url_for_get,
operation_type=AddonOperationType.REDIRECT,
capability=_my_cap.GET_IT,
declaration_cls=_my_interface_cls,
method_name="url_for_get",
)
_expected_put_op = AddonOperation(
operation_fn=_my_interface_cls.url_for_put,
operation_type=AddonOperationType.REDIRECT,
capability=_my_cap.PUT_IT,
declaration_cls=_my_interface_cls,
method_name="url_for_put",
)
_query_operation = AddonOperation(
operation_fn=_my_interface_cls.query_relations,
operation_type=AddonOperationType.PROXY,
capability=_my_cap.GET_IT,
declaration_cls=_my_interface_cls,
Expand Down

0 comments on commit c8b51f5

Please sign in to comment.