diff -r fb0ef164f536 -r 698ae46f40a4 eric6/DebugClients/Python/PyProfile.py --- a/eric6/DebugClients/Python/PyProfile.py Fri Apr 02 11:59:41 2021 +0200 +++ b/eric6/DebugClients/Python/PyProfile.py Sat May 01 14:27:20 2021 +0200 @@ -11,6 +11,7 @@ import profile import atexit import pickle # secok +import contextlib class PyProfile(profile.Profile): @@ -51,24 +52,20 @@ if not os.path.exists(self.timingCache): return - try: - with open(self.timingCache, 'rb') as cache: - timings = marshal.load(cache) # secok - if isinstance(timings, dict): - self.timings = timings - except (OSError, EOFError, ValueError, TypeError): - pass + with contextlib.suppress(OSError, EOFError, ValueError, TypeError), \ + open(self.timingCache, 'rb') as cache: + timings = marshal.load(cache) # secok + if isinstance(timings, dict): + self.timings = timings def save(self): """ Public method to store the collected profile data. """ # dump the raw timing data - try: - with open(self.timingCache, 'wb') as cache: - marshal.dump(self.timings, cache) - except OSError: - pass + with contextlib.suppress(OSError), \ + open(self.timingCache, 'wb') as cache: + marshal.dump(self.timings, cache) # dump the profile data self.dump_stats(self.profileCache) @@ -80,11 +77,9 @@ @param file name of the file to write to (string) """ self.create_stats() - try: - with open(file, 'wb') as f: - pickle.dump(self.stats, f, 4) - except (OSError, pickle.PickleError): - pass + with contextlib.suppress(OSError, pickle.PickleError), \ + open(file, 'wb') as f: + pickle.dump(self.stats, f, 4) def erase(self): """ @@ -143,12 +138,11 @@ if self.cur and frame.f_back is not self.cur[-2]: rpt, rit, ret, rfn, rframe, rcur = self.cur if not isinstance(rframe, profile.Profile.fake_frame): - assert rframe.f_back is frame.f_back, ("Bad call", rfn, - # secok - rframe, rframe.f_back, - frame, frame.f_back) + assert rframe.f_back is frame.f_back, ( # secok + "Bad call", rfn, rframe, rframe.f_back, + frame, frame.f_back) self.trace_dispatch_return(rframe, 0) - assert (self.cur is None or # secok + assert (self.cur is None or # secok frame.f_back is self.cur[-2]), ("Bad call", self.cur[-3]) fcode = frame.f_code