Skip to content

Commit

Permalink
✏️ rename
Browse files Browse the repository at this point in the history
  • Loading branch information
H2Sxxa committed May 12, 2024
1 parent f5acb7e commit f467320
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
12 changes: 7 additions & 5 deletions src/saleyo/operation/hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@ def mixin(self, target: M, toolchain: ToolChain = ToolChain()) -> None:
target_name = (
self.target_name if self.target_name is not None else self.argument.__name__
)
native_function: Callable[..., T] = toolchain.tool_getattr(target, target_name)
original_function: Callable[..., T] = toolchain.tool_getattr(
target, target_name
)

def post(*args, **kwargs) -> Union[T, RT]:
result = native_function(*args, **kwargs)
result = original_function(*args, **kwargs)
post_result = self.argument(result)
if post_result is not None:
return post_result
Expand Down Expand Up @@ -83,12 +85,12 @@ def mixin(self, target: M, toolchain: ToolChain = ToolChain()) -> None:
target_name = (
self.target_name if self.target_name is not None else self.argument.__name__
)
native_function = toolchain.tool_getattr(target, target_name)
original_function = toolchain.tool_getattr(target, target_name)

def pre(*args: P.args, **kwargs: P.kwargs) -> Any:
arguments = self.argument(*args, **kwargs)
if arguments is not None:
return native_function(*arguments.args, **arguments.kwargs)
return native_function(*args, **kwargs)
return original_function(*arguments.args, **arguments.kwargs)
return original_function(*args, **kwargs)

return toolchain.tool_setattr(target, target_name, pre)
6 changes: 3 additions & 3 deletions src/saleyo/operation/intercept.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Intercept(Generic[_PA, _PB], MixinOperation[Callable[[_A[_PA]], _B[_PB]]])
"""
The `Intercept` allow you to intercept the arguments before invoking target method.
Then, you can handle these arguments in your own function and make a redirect to another function.
Then, you can handle thefse arguments in your own function and make a redirect to another function.
If you just want to modify the arguments or the result, please see `Pre` and `Post`.
"""
Expand Down Expand Up @@ -50,7 +50,7 @@ def mixin(
self.target_name if self.target_name is not None else self.argument.__name__
)

native_function = toolchain.tool_getattr(
original_function = toolchain.tool_getattr(
target,
target_name,
)
Expand All @@ -59,6 +59,6 @@ def mixin(
target,
target_name,
lambda *args, **kwargs: self.argument(
InvokeEvent(native_function, *args, **kwargs)
InvokeEvent(original_function, *args, **kwargs)
).invoke_target(),
)

0 comments on commit f467320

Please sign in to comment.