Skip to content

Add validation for callable registration #257

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
May 16, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Refactor registration validation to only allow functions
  • Loading branch information
maelstrom0x8 authored May 16, 2025
commit 61584ce20e17912de07d0307b32abf884e064896
7 changes: 2 additions & 5 deletions resonate/resonate.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,8 @@ def register[**P, R](
version: int = 1,
) -> Function[P, R] | Callable[[Callable[Concatenate[Context, P], R]], Function[P, R]]:
def wrapper(func: Callable[..., Any]) -> Function[P, R]:
if callable(func) and not inspect.isfunction(func) and not inspect.ismethod(func):
if isinstance(func, type):
msg = "Cannot register class types. Register a function, method, or create a function that instantiates the class."
raise ResonateValidationError(msg)
msg = "Cannot register callable objects (instances with __call__ methods). Only functions and methods are supported."
if not inspect.isfunction(func):
msg = "Can only register functions"
raise ResonateValidationError(msg)

self._registry.add(func, name or func.__name__, version)
Expand Down
Loading