diff options
author | Hugo van Kemenade <hugovk@users.noreply.github.com> | 2021-05-03 01:40:05 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-02 15:40:05 -0700 |
commit | df79a6390f6d0531f6411f745d0ccd2c3d674883 (patch) | |
tree | 182575a9f279d791c9a3f724ed8373c750cb49bd /perf | |
parent | bb73791b59f74b6621a87036c14a6be6a23e0e55 (diff) | |
download | python-coveragepy-git-df79a6390f6d0531f6411f745d0ccd2c3d674883.tar.gz |
refactor: remove redundant Python 2 code (#1155)
* Remove Python 2 code
* Upgrade Python syntax with pyupgrade
* Upgrade Python syntax with pyupgrade --py3-plus
* Upgrade Python syntax with pyupgrade --py36-plus
* Remove unused imports
Diffstat (limited to 'perf')
-rw-r--r-- | perf/bug397.py | 3 | ||||
-rw-r--r-- | perf/perf_measure.py | 18 | ||||
-rw-r--r-- | perf/solve_poly.py | 5 |
3 files changed, 12 insertions, 14 deletions
diff --git a/perf/bug397.py b/perf/bug397.py index 390741e5..18c979b8 100644 --- a/perf/bug397.py +++ b/perf/bug397.py @@ -10,7 +10,6 @@ Run this file two ways under coverage and see that the times are the same: Written by David MacIver as part of https://github.com/nedbat/coveragepy/issues/397 """ -from __future__ import print_function import sys import random @@ -52,4 +51,4 @@ if __name__ == '__main__': for d in data: hash_str(d) timing.append(1000000 * (time.time() - start) / len(data)) - print("Runtime per example:", "%.2f +/- %.2f us" % (mean(timing), sd(timing))) + print("Runtime per example:", f"{mean(timing):.2f} +/- {sd(timing):.2f} us") diff --git a/perf/perf_measure.py b/perf/perf_measure.py index 652f0fa8..e8f9ea98 100644 --- a/perf/perf_measure.py +++ b/perf/perf_measure.py @@ -38,15 +38,15 @@ def child(line_count): def mk_main(file_count, call_count, line_count): lines = [] lines.extend( - "import test{}".format(idx) for idx in range(file_count) + f"import test{idx}" for idx in range(file_count) ) lines.extend( - "test{}.parent({}, {})".format(idx, call_count, line_count) for idx in range(file_count) + f"test{idx}.parent({call_count}, {line_count})" for idx in range(file_count) ) return "\n".join(lines) -class StressTest(object): +class StressTest: def __init__(self): self.module_cleaner = SuperModuleCleaner() @@ -55,7 +55,7 @@ class StressTest(object): self.module_cleaner.clean_local_file_imports() for idx in range(file_count): - make_file('test{}.py'.format(idx), TEST_FILE) + make_file(f'test{idx}.py', TEST_FILE) make_file('testmain.py', mk_main(file_count, call_count, line_count)) # Run it once just to get the disk caches loaded up. @@ -137,7 +137,7 @@ class StressTest(object): yield kwargs['file_count'] * kwargs['call_count'] * kwargs['line_count'] ops = sum(sum(operations(thing)) for thing in ["file", "call", "line"]) - print("{:.1f}M operations".format(ops/1e6)) + print(f"{ops/1e6:.1f}M operations") def check_coefficients(self): # For checking the calculation of actual stats: @@ -161,14 +161,14 @@ class StressTest(object): } kwargs[thing+"_count"] = n res = self._compute_overhead(**kwargs) - per_thing.append(res.overhead / getattr(res, "{}s".format(thing))) + per_thing.append(res.overhead / getattr(res, f"{thing}s")) pct_thing.append(res.covered / res.baseline * 100) - out = "Per {}: ".format(thing) + out = f"Per {thing}: " out += "mean = {:9.3f}us, stddev = {:8.3f}us, ".format( statistics.mean(per_thing)*1e6, statistics.stdev(per_thing)*1e6 ) - out += "min = {:9.3f}us, ".format(min(per_thing)*1e6) + out += f"min = {min(per_thing)*1e6:9.3f}us, " out += "pct = {:6.1f}%, stddev = {:6.1f}%".format( statistics.mean(pct_thing), statistics.stdev(pct_thing) ) @@ -181,7 +181,7 @@ class StressTest(object): if __name__ == '__main__': with tempfile.TemporaryDirectory(prefix="coverage_stress_") as tempdir: - print("Working in {}".format(tempdir)) + print(f"Working in {tempdir}") os.chdir(tempdir) sys.path.insert(0, ".") diff --git a/perf/solve_poly.py b/perf/solve_poly.py index 66231725..083dc544 100644 --- a/perf/solve_poly.py +++ b/perf/solve_poly.py @@ -10,7 +10,6 @@ import attr import itertools import numpy import scipy.optimize -import sys def f(*args, simplify=False): @@ -207,7 +206,7 @@ for row in INPUT.splitlines(): #print('\n'.join(str(t) for t in inputs_outputs.items())) def calc_poly_coeff(poly, coefficients): - c_tuples = list(((c,) for c in coefficients)) + c_tuples = list((c,) for c in coefficients) poly = list(f(*poly)) poly = list(a + b for a, b in zip(c_tuples, poly)) multiplied = list(m(*t) for t in poly) @@ -241,7 +240,7 @@ with open('results', 'w') as f: coefficients = [int(round(x)) for x in c.x] terms = [''.join(t) for t in poly.terms] - message = "{}' = ".format(name) + message = f"{name}' = " message += ' + '.join("{}{}".format(coeff if coeff != 1 else '', term) for coeff, term in reversed(list(zip(coefficients, terms))) if coeff != 0) print(message) f.write(message) |