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 all commits
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
8 changes: 7 additions & 1 deletion resonate/resonate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import copy
import functools
import inspect
import random
import time
import uuid
Expand All @@ -12,6 +13,7 @@
from resonate.conventions import Base, Local, Remote, Sleep
from resonate.coroutine import LFC, LFI, RFC, RFI, Promise
from resonate.dependencies import Dependencies
from resonate.errors import ResonateValidationError
from resonate.message_sources import LocalMessageSource, Poller
from resonate.models.handle import Handle
from resonate.options import Options
Expand Down Expand Up @@ -173,7 +175,11 @@ def register[**P, R](
name: str | None = None,
version: int = 1,
) -> Function[P, R] | Callable[[Callable[Concatenate[Context, P], R]], Function[P, R]]:
def wrapper(func: Callable[Concatenate[Context, P], R]) -> Function[P, R]:
def wrapper(func: Callable[..., Any]) -> Function[P, R]:
if not inspect.isfunction(func):
msg = "Can only register functions"
raise ResonateValidationError(msg)

self._registry.add(func, name or func.__name__, version)
return Function(self, name or func.__name__, func, self._opts.merge(version=version))

Expand Down
Loading