Skip to content

Commit

Permalink
Fix validation logic
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianSosic committed Jun 16, 2024
1 parent 38de69a commit d39978b
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions baybe/utils/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,18 @@ def register_hook(target: Callable, hook: Callable) -> Callable:
)

for p1, p2 in zip(target_params, hook_params):
if p1.name != p2.name or p1.annotation != p2.annotation:
if p2.annotation is not inspect.Parameter.empty:
raise TypeError(
f"The signature of '{hook.__name__}' does not match the "
f"signature of '{target.__name__}'."
)
if p1.name != p2.name:
raise TypeError(
f"The parameter names of '{target.__name__}' "
f"and '{hook.__name__}' do not match."
)
if (p1.annotation != p2.annotation) and (
p2.annotation is not inspect.Parameter.empty
):
raise TypeError(
f"The type annotations of '{target.__name__}' "
f"and '{hook.__name__}' do not match."
)

@functools.wraps(target)
def wraps(*args, **kwargs):
Expand Down

0 comments on commit d39978b

Please sign in to comment.