Skip to content

Commit

Permalink
🚑 fix the Pre in hook
Browse files Browse the repository at this point in the history
  • Loading branch information
H2Sxxa committed Mar 15, 2024
1 parent 845086c commit 230a7d2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ foo.demo()

>>> private varible
>>> hello saleyo
>>> pre hello world
>>> hello world
>>> post hello world
>>> pre hello world
```

### Custom Operation
Expand Down
6 changes: 3 additions & 3 deletions src/saleyo/operation/hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__(
Expand All @@ -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,
Expand All @@ -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)

0 comments on commit 230a7d2

Please sign in to comment.