Skip to content

Commit 8171049

Browse files
authored
Fix activity class type hinting when not instantiated (#104)
1 parent 043cdf3 commit 8171049

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

temporalio/converter.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -732,16 +732,17 @@ def _type_hints_from_func(
732732
# the func. This mimics inspect logic inside Python.
733733
if (
734734
not inspect.isfunction(func)
735-
and not isinstance(func, type)
736735
and not isinstance(func, _non_user_defined_callables)
737736
and not isinstance(func, types.MethodType)
738737
):
739-
# Callable instance
740-
call_func = getattr(type(func), "__call__", None)
738+
# Class type or Callable instance
739+
tmp_func = func if isinstance(func, type) else type(func)
740+
call_func = getattr(tmp_func, "__call__", None)
741741
if call_func is not None and not isinstance(
742-
type(func), _non_user_defined_callables
742+
tmp_func, _non_user_defined_callables
743743
):
744744
func = call_func
745+
745746
# We use inspect.signature for the parameter names and kinds, but we cannot
746747
# use it for annotations because those that are using deferred hinting (i.e.
747748
# from __future__ import annotations) only work with the eval_str parameter

tests/test_converter.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,5 +172,6 @@ def assert_hints(func: Any):
172172
assert_hints(some_hinted_func)
173173
assert_hints(some_hinted_func_async)
174174
assert_hints(MyCallableClass())
175+
assert_hints(MyCallableClass)
175176
assert_hints(MyCallableClass.some_method)
176177
assert_hints(MyCallableClass().some_method)

tests/worker/test_workflow.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2081,9 +2081,11 @@ async def __call__(self, to_add: MyDataClass) -> MyDataClass:
20812081
class ActivityCallableClassWorkflow:
20822082
@workflow.run
20832083
async def run(self, to_add: MyDataClass) -> MyDataClass:
2084-
return await workflow.execute_activity_class(
2084+
result = await workflow.execute_activity_class(
20852085
CallableClassActivity, to_add, start_to_close_timeout=timedelta(seconds=30)
20862086
)
2087+
assert isinstance(result, MyDataClass)
2088+
return result
20872089

20882090

20892091
async def test_workflow_activity_callable_class(client: Client):

0 commit comments

Comments
 (0)