2929import os .path as osp
3030import sys
3131import threading
32- from typing import Any
32+ from typing import Any , Dict , NewType , Optional
3333
3434# External packages
3535import pyficache
4444from trepan .processor .cmdproc import CommandProcessor
4545from trepan .processor .trace import PrintProcessor
4646
47+ InitOptions = NewType ("InitOptions" , Dict [str , Any ])
48+
49+ DEFAULT_INIT_OPTS : InitOptions = {
50+ "processor" : None ,
51+ # How many step events to skip before
52+ # entering event processor? Zero (0) means stop at the next one.
53+ # A negative number indicates no eventual stopping.
54+ "step_ignore" : 0 ,
55+ "ignore_filter" : None , # But see debugger.py
56+ }
4757
4858class TrepanCore :
49- DEFAULT_INIT_OPTS = {
50- "processor" : None ,
51- # How many step events to skip before
52- # entering event processor? Zero (0) means stop at the next one.
53- # A negative number indicates no eventual stopping.
54- "step_ignore" : 0 ,
55- "ignore_filter" : None , # But see debugger.py
56- }
57-
58- def __init__ (self , debugger , opts = None ):
59+ def __init__ (self , debugger , opts : InitOptions = DEFAULT_INIT_OPTS ):
5960 """Create a debugger object. But depending on the value of
6061 key 'start' inside hash `opts', we may or may not initially
6162 start tracing events (i.e. enter the debugger).
@@ -64,7 +65,7 @@ def __init__(self, debugger, opts=None):
6465 """
6566
6667 def get_option (key : str ) -> Any :
67- return option_set (opts , key , self . DEFAULT_INIT_OPTS )
68+ return option_set (opts , key , DEFAULT_INIT_OPTS )
6869
6970 self .bpmgr = BreakpointManager ()
7071 self .current_bp = None
@@ -136,9 +137,10 @@ def get_option(key: str) -> Any:
136137
137138 return
138139
139- def add_ignore (self , * frames_or_fns ):
140+ def add_ignore (self , * frames_or_fns ) -> Optional [ Any ] :
140141 """Add `frame_or_fn' to the list of functions that are not to
141142 be debugged"""
143+ rc = None
142144 for frame_or_fn in frames_or_fns :
143145 rc = self .ignore_filter .add (frame_or_fn )
144146 pass
@@ -218,7 +220,7 @@ def remove_ignore(self, frame_or_fn):
218220 be debugged"""
219221 return self .ignore_filter .remove (frame_or_fn )
220222
221- def start (self , opts = None ):
223+ def start (self , opts : InitOptions = DEFAULT_INIT_OPTS ):
222224 """We've already created a debugger object, but here we start
223225 debugging in earnest. We can also turn off debugging (but have
224226 the hooks suspended or not) using 'stop'.
@@ -253,7 +255,7 @@ def get_option(key: str) -> Any:
253255 self .trace_hook_suspend = False
254256 return
255257
256- def stop (self , options = None ):
258+ def stop (self , options = DEFAULT_INIT_OPTS ):
257259 # Our version of:
258260 # sys.settrace(None)
259261 try :
@@ -316,7 +318,6 @@ def is_break_here(self, frame):
316318 return True
317319 else :
318320 return False
319- pass
320321 return False
321322
322323 def matches_condition (self , frame ):
@@ -402,7 +403,7 @@ def set_next(self, frame, step_ignore=0, step_events=None):
402403 """Sets to stop on the next event that happens in frame `frame`.
403404 an raises an exception return to a frame below `frame`
404405 """
405- self .step_events = None # Consider all events
406+ self .step_events = step_events
406407 self .stop_level = count_frames (frame )
407408 self .last_level = self .stop_level
408409 self .last_frame = frame
@@ -422,7 +423,7 @@ def trace_dispatch(self, frame, event: str, arg):
422423
423424 # Check to see if are in a call but we should be stepping over the call
424425 # using "next" of "finish". If so, then we can speed tracing by
425- # removing futher tracing. Not though that we *also* must make sure
426+ # removing further tracing. Not though that we *also* must make sure
426427 # that we don't have any breakpoint set, since we have to check
427428 # for breakpoints in a kind of slow way of checking all events.
428429
@@ -499,7 +500,6 @@ def trace_dispatch(self, frame, event: str, arg):
499500 except Exception :
500501 pass
501502 pass
502- pass
503503
504504 pass
505505
@@ -510,7 +510,7 @@ def trace_dispatch(self, frame, event: str, arg):
510510 class MockProcessor :
511511 pass
512512
513- opts = {"processor" : MockProcessor ()}
513+ opts : InitOptions = {"processor" : MockProcessor ()}
514514 dc = TrepanCore (None , opts = opts )
515515 dc .step_ignore = 1
516516 print ("dc._is_step_next_stop():" , dc ._is_step_next_stop ("line" ))
0 commit comments