From b7b03889d65d51adaf43b4560f130156a8ad65cf Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Sun, 23 Jan 2022 17:33:09 -0500 Subject: [PATCH] Make `mypy` happy --- tractor/_debug.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tractor/_debug.py b/tractor/_debug.py index af66143..f70502e 100644 --- a/tractor/_debug.py +++ b/tractor/_debug.py @@ -30,6 +30,7 @@ from typing import ( Callable, AsyncIterator, AsyncGenerator, + Iterator, ) import tractor @@ -483,7 +484,7 @@ async def _breakpoint( @cm -def _open_pdb() -> PdbwTeardown: +def _open_pdb() -> Iterator[PdbwTeardown]: # XXX: setting these flags on the pdb instance are absolutely # critical to having ctrl-c work in the ``trio`` standard way! The @@ -498,7 +499,8 @@ def _open_pdb() -> PdbwTeardown: try: yield pdb except bdb.BdbQuit: - _pdb_release_hook() + if _pdb_release_hook: + _pdb_release_hook() raise @@ -592,13 +594,16 @@ def shield_sigint( def disable_sigint( pdb: Optional[PdbwTeardown] = None -) -> None: +) -> Iterator[None]: + __tracebackhide__ = True # ensure the ``contextlib.contextmanager`` frame inside the wrapping # ``.__exit__()`` method isn't shown either. frame = sys._getframe() - frame.f_back.f_globals['__tracebackhide__'] = True + last_f = frame.f_back + if last_f: + last_f.f_globals['__tracebackhide__'] = True # NOTE: this seems like a form of cpython bug wherein # it's likely that ``functools.WRAPPER_ASSIGNMENTS`` should # probably contain this attr name?