Skip to content
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

More consistent handler decorators #557

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
34 changes: 25 additions & 9 deletions temporalio/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,13 @@ def signal(fn: CallableSyncOrAsyncReturnNoneType) -> CallableSyncOrAsyncReturnNo
...


@overload
def signal() -> (
Callable[[CallableSyncOrAsyncReturnNoneType], CallableSyncOrAsyncReturnNoneType]
):
...


@overload
def signal(
*, name: str
Expand Down Expand Up @@ -232,12 +239,10 @@ def with_name(
)
return fn

if name is not None or dynamic:
if not fn:
if name is not None and dynamic:
raise RuntimeError("Cannot provide name and dynamic boolean")
return partial(with_name, name)
if fn is None:
raise RuntimeError("Cannot create signal without function or name or dynamic")
return with_name(fn.__name__, fn)


Expand All @@ -246,6 +251,11 @@ def query(fn: CallableType) -> CallableType:
...


@overload
def query() -> Callable[[CallableType], CallableType]:
...


@overload
def query(*, name: str) -> Callable[[CallableType], CallableType]:
...
Expand Down Expand Up @@ -302,12 +312,10 @@ def with_name(
)
return fn

if name is not None or dynamic:
if not fn:
if name is not None and dynamic:
raise RuntimeError("Cannot provide name and dynamic boolean")
return partial(with_name, name)
if fn is None:
raise RuntimeError("Cannot create query without function or name or dynamic")
if inspect.iscoroutinefunction(fn):
warnings.warn(
"Queries as async def functions are deprecated",
Expand Down Expand Up @@ -921,6 +929,16 @@ def update(
...


@overload
def update() -> (
Callable[
[Callable[MultiParamSpec, ReturnType]],
UpdateMethodMultiParam[MultiParamSpec, ReturnType],
]
):
...


@overload
def update(
*, name: str
Expand Down Expand Up @@ -987,12 +1005,10 @@ def with_name(
setattr(fn, "validator", partial(_update_validator, defn))
return fn

if name is not None or dynamic:
if not fn:
if name is not None and dynamic:
raise RuntimeError("Cannot provide name and dynamic boolean")
return partial(with_name, name)
if fn is None:
raise RuntimeError("Cannot create update without function or name or dynamic")
return with_name(fn.__name__, fn)


Expand Down
12 changes: 12 additions & 0 deletions tests/test_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ def signal2(self):
def signal3(self, name: str, args: Sequence[RawValue]):
pass

@workflow.signal()
def signal4(self):
pass

@workflow.query
def query1(self):
pass
Expand All @@ -54,6 +58,10 @@ def query2(self):
def query3(self, name: str, args: Sequence[RawValue]):
pass

@workflow.query()
def query4(self):
pass

@workflow.update
def update1(self):
pass
Expand All @@ -66,6 +74,10 @@ def update2(self):
def update3(self, name: str, args: Sequence[RawValue]):
pass

@workflow.update()
def update4(self):
pass


def test_workflow_defn_good():
# Although the API is internal, we want to check the literal definition just
Expand Down
Loading