From b9eb601265ea2f2fef0ea50983c1a6454119ebad Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Mon, 11 Jul 2022 09:42:26 -0400 Subject: [PATCH] General typing fixes for `mypy` --- tractor/_debug.py | 7 ++++--- tractor/_spawn.py | 6 +++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/tractor/_debug.py b/tractor/_debug.py index 3544f6f..046a896 100644 --- a/tractor/_debug.py +++ b/tractor/_debug.py @@ -739,13 +739,14 @@ def _set_trace( # last_f.f_globals['__tracebackhide__'] = True # start 2 levels up in user code - frame: FrameType = sys._getframe() + frame: Optional[FrameType] = sys._getframe() if frame: frame = frame.f_back # type: ignore - if pdb and actor is not None: + if frame and pdb and actor is not None: log.pdb(f"\nAttaching pdb to actor: {actor.uid}\n") - # no f!#$&* idea! + # no f!#$&* idea, but when we're in async land + # we need 2x frames up? frame = frame.f_back else: diff --git a/tractor/_spawn.py b/tractor/_spawn.py index eba6456..4230bfb 100644 --- a/tractor/_spawn.py +++ b/tractor/_spawn.py @@ -307,7 +307,8 @@ async def new_proc( proc: Optional[trio.Process] = None try: try: - proc = await trio.lowlevel.open_process(spawn_cmd) + # TODO: needs ``trio_typing`` patch? + proc = await trio.lowlevel.open_process(spawn_cmd) # type: ignore log.runtime(f"Started {proc}") @@ -334,6 +335,9 @@ async def new_proc( await proc.wait() raise + # a sub-proc ref **must** exist now + assert proc + portal = Portal(chan) actor_nursery._children[subactor.uid] = ( subactor, proc, portal)