From c375a2d028e727b41d45cd65ebb2af836e541682 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Tue, 13 Oct 2020 11:03:55 -0400 Subject: [PATCH] mypy fixes --- tractor/__init__.py | 5 ++++- tractor/_actor.py | 2 +- tractor/_debug.py | 12 ++++++------ tractor/_state.py | 6 +++--- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/tractor/__init__.py b/tractor/__init__.py index b65811a..d3aedc4 100644 --- a/tractor/__init__.py +++ b/tractor/__init__.py @@ -17,6 +17,7 @@ from ._discovery import get_arbiter, find_actor, wait_for_actor from ._actor import Actor, _start_actor, Arbiter from ._trionics import open_nursery from ._state import current_actor +from . import _state from ._exceptions import RemoteActorError, ModuleNotExposed from ._debug import breakpoint, post_mortem from . import msg @@ -24,6 +25,8 @@ from . import _spawn __all__ = [ + 'breakpoint', + 'post_mortem', 'current_actor', 'find_actor', 'get_arbiter', @@ -51,7 +54,7 @@ async def _main( name: Optional[str] = None, start_method: Optional[str] = None, debug_mode: bool = False, - **kwargs: typing.Dict[str, typing.Any], + **kwargs, ) -> typing.Any: """Async entry point for ``tractor``. """ diff --git a/tractor/_actor.py b/tractor/_actor.py index 74c2049..80a7dd5 100644 --- a/tractor/_actor.py +++ b/tractor/_actor.py @@ -249,7 +249,7 @@ class Actor: self._parent_chan: Optional[Channel] = None self._forkserver_info: Optional[ Tuple[Any, Any, Any, Any, Any]] = None - self._actoruid2nursery: Dict[str, 'ActorNursery'] = {} # noqa + self._actoruid2nursery: Dict[str, 'ActorNursery'] = {} # type: ignore async def wait_for_peer( self, uid: Tuple[str, str] diff --git a/tractor/_debug.py b/tractor/_debug.py index 04c9637..29c0430 100644 --- a/tractor/_debug.py +++ b/tractor/_debug.py @@ -5,7 +5,7 @@ import bdb import sys from functools import partial from contextlib import asynccontextmanager -from typing import Awaitable, Tuple, Optional, Callable +from typing import Awaitable, Tuple, Optional, Callable, AsyncIterator # import signal from async_generator import aclosing @@ -22,9 +22,9 @@ try: # wtf: only exported when installed in dev mode? import pdbpp except ImportError: - # pdbpp is installed in regular mode... + # pdbpp is installed in regular mode...it monkey patches stuff import pdb - assert pdb.xpm, "pdbpp is not installed?" + assert pdb.xpm, "pdbpp is not installed?" # type: ignore pdbpp = pdb log = get_logger(__name__) @@ -45,7 +45,7 @@ _debug_lock = trio.StrictFIFOLock() # XXX: set by the current task waiting on the root tty lock # and must be cancelled if this actor is cancelled via message # otherwise deadlocks with the parent actor may ensure -_debugger_request_cs: trio.CancelScope = None +_debugger_request_cs: Optional[trio.CancelScope] = None class TractorConfig(pdbpp.DefaultConfig): @@ -117,7 +117,7 @@ class PdbwTeardown(pdbpp.Pdb): @asynccontextmanager -async def _acquire_debug_lock(uid: Tuple[str, str]) -> None: +async def _acquire_debug_lock(uid: Tuple[str, str]) -> AsyncIterator[None]: """Acquire a actor local FIFO lock meant to mutex entry to a local debugger entry point to avoid tty clobbering by multiple processes. """ @@ -158,7 +158,7 @@ pdbpp.pdb.Pdb.sigint_handler = handler async def _hijack_stdin_relay_to_child( subactor_uid: Tuple[str, str] -) -> None: +) -> AsyncIterator[str]: # TODO: when we get to true remote debugging # this will deliver stdin data log.warning(f"Actor {subactor_uid} is WAITING on stdin hijack lock") diff --git a/tractor/_state.py b/tractor/_state.py index 2728b78..03ddf13 100644 --- a/tractor/_state.py +++ b/tractor/_state.py @@ -1,14 +1,14 @@ """ Per process state """ -from typing import Optional +from typing import Optional, Dict, Any from collections import Mapping import multiprocessing as mp import trio _current_actor: Optional['Actor'] = None # type: ignore -_runtime_vars = { +_runtime_vars: Dict[str, Any] = { '_debug_mode': False, '_is_root': False, '_root_mailbox': (None, None) @@ -54,7 +54,7 @@ def debug_mode() -> bool: """Bool determining if "debug mode" is on which enables remote subactor pdb entry on crashes. """ - return _runtime_vars['_debug_mode'] + return bool(_runtime_vars['_debug_mode']) def is_root_process() -> bool: