From 83af295b450155b861c06e04ea71cd1087fed178 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Wed, 28 Apr 2021 11:38:31 -0400 Subject: [PATCH] Fix func type checking --- tractor/_portal.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/tractor/_portal.py b/tractor/_portal.py index d2db1f0..d82e040 100644 --- a/tractor/_portal.py +++ b/tractor/_portal.py @@ -110,8 +110,10 @@ class Portal: return cid, recv_chan, functype, first_msg async def _submit_for_result(self, ns: str, func: str, **kwargs) -> None: + assert self._expect_result is None, \ "A pending main result has already been submitted" + self._expect_result = await self._submit(ns, func, kwargs) async def _return_once( @@ -266,10 +268,15 @@ class Portal: assert isinstance(fn_name, str) else: # function reference was passed directly - if not ( - inspect.iscoroutinefunction(func) + if ( + not inspect.iscoroutinefunction(func) or + ( + inspect.iscoroutinefunction(func) and + getattr(func, '_tractor_stream_function', False) + ) ): - raise TypeError(f'{func} must be an async function!') + raise TypeError( + f'{func} must be a non-streaming async function!') fn_mod_path, fn_name = func_deats(func) @@ -285,8 +292,9 @@ class Portal: ) -> AsyncGenerator[ReceiveMsgStream, None]: if not inspect.isasyncgenfunction(async_gen_func): - if not inspect.iscoroutinefunction(async_gen_func) or ( - not getattr(async_gen_func, '_tractor_stream_function', False) + if not ( + inspect.iscoroutinefunction(async_gen_func) and + getattr(async_gen_func, '_tractor_stream_function', False) ): raise TypeError( f'{async_gen_func} must be an async generator function!')