Skip to content

Commit f35c6ba

Browse files
authored
Merge pull request #129 from stealthrocket/function-name-fix
Fix registration of synchronous functions
2 parents 8aa6795 + 988c45e commit f35c6ba

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

src/dispatch/function.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -182,28 +182,28 @@ def function(self, func: Callable[P, T]) -> Function[P, T]: ...
182182

183183
def function(self, func):
184184
"""Decorator that registers functions."""
185+
name = func.__qualname__
185186
if not inspect.iscoroutinefunction(func):
186-
logger.info("registering function: %s", func.__qualname__)
187-
return self._register_function(func)
187+
logger.info("registering function: %s", name)
188+
return self._register_function(name, func)
188189

189-
logger.info("registering coroutine: %s", func.__qualname__)
190-
return self._register_coroutine(func)
190+
logger.info("registering coroutine: %s", name)
191+
return self._register_coroutine(name, func)
191192

192-
def _register_function(self, func: Callable[P, T]) -> Function[P, T]:
193+
def _register_function(self, name: str, func: Callable[P, T]) -> Function[P, T]:
193194
func = durable(func)
194195

195196
@wraps(func)
196197
async def async_wrapper(*args: P.args, **kwargs: P.kwargs) -> T:
197198
return func(*args, **kwargs)
198199

199-
async_wrapper.__qualname__ = f"{func.__qualname__}_async"
200+
async_wrapper.__qualname__ = f"{name}_async"
200201

201-
return self._register_coroutine(async_wrapper)
202+
return self._register_coroutine(name, async_wrapper)
202203

203204
def _register_coroutine(
204-
self, func: Callable[P, Coroutine[Any, Any, T]]
205+
self, name: str, func: Callable[P, Coroutine[Any, Any, T]]
205206
) -> Function[P, T]:
206-
name = func.__qualname__
207207
logger.info("registering coroutine: %s", name)
208208

209209
func = durable(func)

tests/test_full.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ def test_simple_end_to_end(self):
5959
def my_function(name: str) -> str:
6060
return f"Hello world: {name}"
6161

62+
call = my_function.build_call(52)
63+
self.assertEqual(call.function.split(".")[-1], "my_function")
64+
6265
# The client.
6366
[dispatch_id] = self.dispatch_client.dispatch([my_function.build_call(52)])
6467

@@ -73,10 +76,13 @@ def my_function(name: str) -> str:
7376

7477
def test_simple_missing_signature(self):
7578
@self.dispatch.function
76-
def my_function(name: str) -> str:
79+
async def my_function(name: str) -> str:
7780
return f"Hello world: {name}"
7881

79-
[dispatch_id] = self.dispatch_client.dispatch([my_function.build_call(52)])
82+
call = my_function.build_call(52)
83+
self.assertEqual(call.function.split(".")[-1], "my_function")
84+
85+
[dispatch_id] = self.dispatch_client.dispatch([call])
8086

8187
self.dispatch_service.endpoint_client = EndpointClient.from_app(
8288
self.endpoint_app

0 commit comments

Comments
 (0)