From 230a7d2074e383847538e9bd36aaa87f5efa9d73 Mon Sep 17 00:00:00 2001 From: H2Sxxa Date: Fri, 15 Mar 2024 16:29:55 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=91=20fix=20the=20`Pre`=20in=20`hook`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- src/saleyo/operation/hook.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 073d41e..6fc09c5 100644 --- a/README.md +++ b/README.md @@ -74,9 +74,9 @@ foo.demo() >>> private varible >>> hello saleyo +>>> pre hello world >>> hello world >>> post hello world ->>> pre hello world ``` ### Custom Operation diff --git a/src/saleyo/operation/hook.py b/src/saleyo/operation/hook.py index 2017370..50f0164 100644 --- a/src/saleyo/operation/hook.py +++ b/src/saleyo/operation/hook.py @@ -50,6 +50,7 @@ class Pre(MixinOperation[Callable[..., RT]]): """ `Pre` will call before the target method, and the callable should be decorated as `@staticmethod` and have `*args,**kwargs` to receive the arguments of target method. """ + target_name: Optional[str] def __init__( @@ -66,7 +67,7 @@ def configure( level: int = 1, target_name: Optional[str] = None, ): - return lambda argument: Post( + return lambda argument: Pre( argument=argument, target_name=target_name, level=level, @@ -80,7 +81,6 @@ def mixin(self, target: Type, toolchain: ToolChain = ToolChain()) -> None: def pre(*args, **kwargs): self.argument(*args, **kwargs) - result = native_function(*args, **kwargs) - return result + return native_function(*args, **kwargs) return toolchain.tool_setattr(target, target_name, pre)