From fde52d246438aa3ab6cafea943689532e548d4fd Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Thu, 8 Jul 2021 12:48:34 -0400 Subject: [PATCH] Mypy fixes --- tractor/_actor.py | 2 +- tractor/_portal.py | 16 ++++++---------- tractor/_streaming.py | 3 +++ 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/tractor/_actor.py b/tractor/_actor.py index 4359e13..c45449d 100644 --- a/tractor/_actor.py +++ b/tractor/_actor.py @@ -64,7 +64,7 @@ async def _invoke( tb = None cancel_scope = trio.CancelScope() - cs: trio.CancelScope = None + cs: Optional[trio.CancelScope] = None ctx = Context(chan, cid) context: bool = False diff --git a/tractor/_portal.py b/tractor/_portal.py index 4471c8f..44e8630 100644 --- a/tractor/_portal.py +++ b/tractor/_portal.py @@ -391,9 +391,8 @@ class Portal: else: raise - _err = None - # deliver context instance and .started() msg value in open - # tuple. + _err: Optional[BaseException] = None + # deliver context instance and .started() msg value in open tuple. try: async with trio.open_nursery() as scope_nursery: ctx = Context( @@ -403,16 +402,13 @@ class Portal: _recv_chan=recv_chan, _scope_nursery=scope_nursery, ) - recv_chan._ctx = ctx + + # pairs with handling in ``Actor._push_result()`` + # recv_chan._ctx = ctx # await trio.lowlevel.checkpoint() yield ctx, first - # if not ctx._cancel_called: - # await ctx.result() - - # await recv_chan.aclose() - except ContextCancelled as err: _err = err if not ctx._cancel_called: @@ -462,7 +458,7 @@ class Portal: else: log.info( f'Context {fn_name} returned ' - f'value from callee `{self._result}`' + f'value from callee `{result}`' ) diff --git a/tractor/_streaming.py b/tractor/_streaming.py index f23376a..eead6f6 100644 --- a/tractor/_streaming.py +++ b/tractor/_streaming.py @@ -332,6 +332,8 @@ class Context: Acts as a form of "relay" for a remote error raised in the corresponding remote callee task. ''' + assert self._scope_nursery + async def raiser(): raise unpack_error(msg, self.chan) @@ -385,6 +387,7 @@ class Context: # {'error': trio.Cancelled, cid: "blah"} enough? # This probably gets into the discussion in # https://github.com/goodboy/tractor/issues/36 + assert self._scope_nursery self._scope_nursery.cancel_scope.cancel() if self._recv_chan: