Annotate nursery and portal methods for `CallerInfo` scanning

runtime_to_msgspec
Tyler Goodlet 2024-04-18 15:17:50 -04:00
parent 5439060cd3
commit d2f6428e46
2 changed files with 29 additions and 7 deletions

View File

@ -161,17 +161,18 @@ class Portal:
self._expect_result = await self.actor.start_remote_task(
self.channel,
nsf=NamespacePath(f'{ns}:{func}'),
kwargs=kwargs
kwargs=kwargs,
portal=self,
)
async def _return_once(
self,
ctx: Context,
) -> dict[str, Any]:
) -> Return:
assert ctx._remote_func_type == 'asyncfunc' # single response
msg: dict = await ctx._recv_chan.receive()
msg: Return = await ctx._recv_chan.receive()
return msg
async def result(self) -> Any:
@ -247,6 +248,8 @@ class Portal:
purpose.
'''
__runtimeframe__: int = 1 # noqa
chan: Channel = self.channel
if not chan.connected():
log.runtime(
@ -324,16 +327,18 @@ class Portal:
internals!
'''
__runtimeframe__: int = 1 # noqa
nsf = NamespacePath(
f'{namespace_path}:{function_name}'
)
ctx = await self.actor.start_remote_task(
ctx: Context = await self.actor.start_remote_task(
chan=self.channel,
nsf=nsf,
kwargs=kwargs,
portal=self,
)
ctx._portal = self
msg = await self._return_once(ctx)
ctx._portal: Portal = self
msg: Return = await self._return_once(ctx)
return _unwrap_msg(
msg,
self.channel,
@ -384,6 +389,7 @@ class Portal:
self.channel,
nsf=nsf,
kwargs=kwargs,
portal=self,
)
ctx._portal = self
return _unwrap_msg(
@ -398,6 +404,14 @@ class Portal:
**kwargs,
) -> AsyncGenerator[MsgStream, None]:
'''
Legacy one-way streaming API.
TODO: re-impl on top `Portal.open_context()` + an async gen
around `Context.open_stream()`.
'''
__runtimeframe__: int = 1 # noqa
if not inspect.isasyncgenfunction(async_gen_func):
if not (
@ -411,6 +425,7 @@ class Portal:
self.channel,
nsf=NamespacePath.from_ref(async_gen_func),
kwargs=kwargs,
portal=self,
)
ctx._portal = self

View File

@ -131,7 +131,12 @@ class ActorNursery:
"main task" besides the runtime.
'''
loglevel = loglevel or self._actor.loglevel or get_loglevel()
__runtimeframe__: int = 1 # noqa
loglevel: str = (
loglevel
or self._actor.loglevel
or get_loglevel()
)
# configure and pass runtime state
_rtv = _state._runtime_vars.copy()
@ -209,6 +214,7 @@ class ActorNursery:
the actor is terminated.
'''
__runtimeframe__: int = 1 # noqa
mod_path: str = fn.__module__
if name is None:
@ -257,6 +263,7 @@ class ActorNursery:
directly without any far end graceful ``trio`` cancellation.
'''
__runtimeframe__: int = 1 # noqa
self.cancelled = True
# TODO: impl a repr for spawn more compact