--- a/eric7/DebugClients/Python/coverage/pytracer.py Fri Nov 19 19:28:47 2021 +0100 +++ b/eric7/DebugClients/Python/coverage/pytracer.py Sat Nov 20 16:47:38 2021 +0100 @@ -11,8 +11,6 @@ # We need the YIELD_VALUE opcode below, in a comparison-friendly form. YIELD_VALUE = dis.opmap['YIELD_VALUE'] -if env.PY2: - YIELD_VALUE = chr(YIELD_VALUE) # When running meta-coverage, this file can try to trace itself, which confuses # everything. Don't trace ourselves. @@ -20,7 +18,7 @@ THIS_FILE = __file__.rstrip("co") -class PyTracer(object): +class PyTracer: """Python implementation of the raw data tracer.""" # Because of poor implementations of trace-function-manipulating tools, @@ -50,15 +48,13 @@ # The threading module to use, if any. self.threading = None - self.cur_file_dict = None + self.cur_file_data = None self.last_line = 0 # int, but uninitialized. self.cur_file_name = None self.context = None self.started_context = False self.data_stack = [] - self.last_exc_back = None - self.last_exc_firstlineno = 0 self.thread = None self.stopped = False self._activity = False @@ -85,7 +81,7 @@ if 0: f.write(".{:x}.{:x}".format( self.thread.ident, - self.threading.currentThread().ident, + self.threading.current_thread().ident, )) f.write(" {}".format(" ".join(map(str, args)))) if 0: @@ -115,22 +111,11 @@ self.log(">", f.f_code.co_filename, f.f_lineno, f.f_code.co_name, f.f_trace) f = f.f_back sys.settrace(None) - self.cur_file_dict, self.cur_file_name, self.last_line, self.started_context = ( + self.cur_file_data, self.cur_file_name, self.last_line, self.started_context = ( self.data_stack.pop() ) return None - if self.last_exc_back: - if frame == self.last_exc_back: - # Someone forgot a return event. - if self.trace_arcs and self.cur_file_dict: - pair = (self.last_line, -self.last_exc_firstlineno) - self.cur_file_dict[pair] = None - self.cur_file_dict, self.cur_file_name, self.last_line, self.started_context = ( - self.data_stack.pop() - ) - self.last_exc_back = None - # if event != 'call' and frame.f_code.co_filename != self.cur_file_name: # self.log("---\n*", frame.f_code.co_filename, self.cur_file_name, frame.f_lineno) @@ -152,7 +137,7 @@ self._activity = True self.data_stack.append( ( - self.cur_file_dict, + self.cur_file_data, self.cur_file_name, self.last_line, self.started_context, @@ -165,12 +150,12 @@ disp = self.should_trace(filename, frame) self.should_trace_cache[filename] = disp - self.cur_file_dict = None + self.cur_file_data = None if disp.trace: tracename = disp.source_filename if tracename not in self.data: - self.data[tracename] = {} - self.cur_file_dict = self.data[tracename] + self.data[tracename] = set() + self.cur_file_data = self.data[tracename] # The call event is really a "start frame" event, and happens for # function calls and re-entering generators. The f_lasti field is # -1 for calls, and a real offset for generators. Use <0 as the @@ -181,34 +166,31 @@ self.last_line = frame.f_lineno elif event == 'line': # Record an executed line. - if self.cur_file_dict is not None: + if self.cur_file_data is not None: lineno = frame.f_lineno if self.trace_arcs: - self.cur_file_dict[(self.last_line, lineno)] = None + self.cur_file_data.add((self.last_line, lineno)) else: - self.cur_file_dict[lineno] = None + self.cur_file_data.add(lineno) self.last_line = lineno elif event == 'return': - if self.trace_arcs and self.cur_file_dict: + if self.trace_arcs and self.cur_file_data: # Record an arc leaving the function, but beware that a # "return" event might just mean yielding from a generator. # Jython seems to have an empty co_code, so just assume return. code = frame.f_code.co_code if (not code) or code[frame.f_lasti] != YIELD_VALUE: first = frame.f_code.co_firstlineno - self.cur_file_dict[(self.last_line, -first)] = None + self.cur_file_data.add((self.last_line, -first)) # Leaving this function, pop the filename stack. - self.cur_file_dict, self.cur_file_name, self.last_line, self.started_context = ( + self.cur_file_data, self.cur_file_name, self.last_line, self.started_context = ( self.data_stack.pop() ) # Leaving a context? if self.started_context: self.context = None self.switch_context(None) - elif event == 'exception': - self.last_exc_back = frame.f_back - self.last_exc_firstlineno = frame.f_code.co_firstlineno return self._trace def start(self): @@ -220,9 +202,9 @@ self.stopped = False if self.threading: if self.thread is None: - self.thread = self.threading.currentThread() + self.thread = self.threading.current_thread() else: - if self.thread.ident != self.threading.currentThread().ident: + if self.thread.ident != self.threading.current_thread().ident: # Re-starting from a different thread!? Don't set the trace # function, but we are marked as running again, so maybe it # will be ok? @@ -243,7 +225,7 @@ # right thread. self.stopped = True - if self.threading and self.thread.ident != self.threading.currentThread().ident: + if self.threading and self.thread.ident != self.threading.current_thread().ident: # Called on a different thread than started us: we can't unhook # ourselves, but we've set the flag that we should stop, so we # won't do any more tracing. @@ -256,10 +238,8 @@ # has changed to None. dont_warn = (env.PYPY and env.PYPYVERSION >= (5, 4) and self.in_atexit and tf is None) if (not dont_warn) and tf != self._trace: # pylint: disable=comparison-with-callable - self.warn( - "Trace function changed, measurement is likely wrong: %r" % (tf,), - slug="trace-changed", - ) + msg = f"Trace function changed, measurement is likely wrong: {tf!r}" + self.warn(msg, slug="trace-changed") def activity(self): """Has there been any activity?"""