From: Simon Marchi Date: Wed, 29 Oct 2025 17:49:25 +0000 (-0400) Subject: gdb/testsuite: avoid assigning lambdas in Python files X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b58e2ff69ae7050590be0fc933aa822e41b39519;p=thirdparty%2Fbinutils-gdb.git gdb/testsuite: avoid assigning lambdas in Python files Fix flake8 warnings like this one: gdb/testsuite/gdb.perf/template-breakpoints.py:35:13: E731 do not assign a lambda expression, use a def I chose to inline the lambdas in the expressions, since they are simple enough and only used once each. Change-Id: I46fac428a95da38f5a6a87e101be4da9fa4acc31 Approved-By: Tom Tromey --- diff --git a/gdb/testsuite/gdb.perf/backtrace.py b/gdb/testsuite/gdb.perf/backtrace.py index e3d3e91418c..a764e4c1b05 100644 --- a/gdb/testsuite/gdb.perf/backtrace.py +++ b/gdb/testsuite/gdb.perf/backtrace.py @@ -45,8 +45,6 @@ class BackTrace(perftest.TestCaseWithBasicMeasurements): gdb.execute(line_size_command) gdb.execute(size_command) - func = lambda: self._do_test() - - self.measure.measure(func, line_size) + self.measure.measure(self._do_test, line_size) line_size *= 2 diff --git a/gdb/testsuite/gdb.perf/gmonster-null-lookup.py b/gdb/testsuite/gdb.perf/gmonster-null-lookup.py index 825632329d4..e12377180f6 100644 --- a/gdb/testsuite/gdb.perf/gmonster-null-lookup.py +++ b/gdb/testsuite/gdb.perf/gmonster-null-lookup.py @@ -39,6 +39,7 @@ class NullLookup(perftest.TestCaseWithBasicMeasurements): iteration = 5 while iteration > 0: utils.safe_execute("mt flush symbol-cache") - func = lambda: utils.safe_execute("p symbol_not_found") - self.measure.measure(func, run) + self.measure.measure( + lambda: utils.safe_execute("p symbol_not_found"), run + ) iteration -= 1 diff --git a/gdb/testsuite/gdb.perf/gmonster-print-cerr.py b/gdb/testsuite/gdb.perf/gmonster-print-cerr.py index 0f201b3e27e..de80c039c65 100644 --- a/gdb/testsuite/gdb.perf/gmonster-print-cerr.py +++ b/gdb/testsuite/gdb.perf/gmonster-print-cerr.py @@ -45,6 +45,7 @@ class PrintCerr(perftest.TestCaseWithBasicMeasurements): iteration = 5 while iteration > 0: utils.safe_execute("mt flush symbol-cache") - func = lambda: utils.safe_execute("print gm_std::cerr") - self.measure.measure(func, run) + self.measure.measure( + lambda: utils.safe_execute("print gm_std::cerr"), run + ) iteration -= 1 diff --git a/gdb/testsuite/gdb.perf/gmonster-ptype-string.py b/gdb/testsuite/gdb.perf/gmonster-ptype-string.py index 3397b123a1e..0b1938cfd99 100644 --- a/gdb/testsuite/gdb.perf/gmonster-ptype-string.py +++ b/gdb/testsuite/gdb.perf/gmonster-ptype-string.py @@ -40,7 +40,10 @@ class GmonsterPtypeString(perftest.TestCaseWithBasicMeasurements): iteration = 5 while iteration > 0: utils.safe_execute("mt flush symbol-cache") - func1 = lambda: utils.safe_execute("ptype hello") - func = lambda: utils.run_n_times(2, func1) - self.measure.measure(func, run) + self.measure.measure( + lambda: utils.run_n_times( + 2, lambda: utils.safe_execute("ptype hello") + ), + run, + ) iteration -= 1 diff --git a/gdb/testsuite/gdb.perf/gmonster-runto-main.py b/gdb/testsuite/gdb.perf/gmonster-runto-main.py index 097c32a1bdd..f5782ae4a13 100644 --- a/gdb/testsuite/gdb.perf/gmonster-runto-main.py +++ b/gdb/testsuite/gdb.perf/gmonster-runto-main.py @@ -33,6 +33,5 @@ class GmonsterRuntoMain(perftest.TestCaseWithBasicMeasurements): utils.select_file(this_run_binfile) iteration = 5 while iteration > 0: - func = lambda: utils.runto_main() - self.measure.measure(func, run) + self.measure.measure(lambda: utils.runto_main(), run) iteration -= 1 diff --git a/gdb/testsuite/gdb.perf/gmonster-select-file.py b/gdb/testsuite/gdb.perf/gmonster-select-file.py index 05db3624dac..6ac77858cb4 100644 --- a/gdb/testsuite/gdb.perf/gmonster-select-file.py +++ b/gdb/testsuite/gdb.perf/gmonster-select-file.py @@ -36,6 +36,5 @@ class GmonsterSelectFile(perftest.TestCaseWithBasicMeasurements): this_run_binfile = "%s-%s" % (self.binfile, utils.convert_spaces(run)) iteration = 5 while iteration > 0: - func = lambda: self._doit(this_run_binfile) - self.measure.measure(func, run) + self.measure.measure(lambda: self._doit(this_run_binfile), run) iteration -= 1 diff --git a/gdb/testsuite/gdb.perf/single-step.py b/gdb/testsuite/gdb.perf/single-step.py index eecf2f982a0..27d3e053d51 100644 --- a/gdb/testsuite/gdb.perf/single-step.py +++ b/gdb/testsuite/gdb.perf/single-step.py @@ -33,5 +33,4 @@ class SingleStep(perftest.TestCaseWithBasicMeasurements): def execute_test(self): for i in range(1, 5): - func = lambda: self._run(i * self.step) - self.measure.measure(func, i * self.step) + self.measure.measure(lambda: self._run(i * self.step), i * self.step) diff --git a/gdb/testsuite/gdb.perf/skip-command.py b/gdb/testsuite/gdb.perf/skip-command.py index b344c9c36a3..5614aebc75d 100644 --- a/gdb/testsuite/gdb.perf/skip-command.py +++ b/gdb/testsuite/gdb.perf/skip-command.py @@ -33,5 +33,4 @@ class SkipCommand(perftest.TestCaseWithBasicMeasurements): def execute_test(self): for i in range(1, 5): - func = lambda: self._run(i * self.step) - self.measure.measure(func, i * self.step) + self.measure.measure(lambda: self._run(i * self.step), i * self.step) diff --git a/gdb/testsuite/gdb.perf/solib.py b/gdb/testsuite/gdb.perf/solib.py index c440635147b..1f780146591 100644 --- a/gdb/testsuite/gdb.perf/solib.py +++ b/gdb/testsuite/gdb.perf/solib.py @@ -47,9 +47,7 @@ class SolibLoadUnload1(perftest.TestCaseWithBasicMeasurements): # but measure differently. if self.measure_load: do_test_load = "call do_test_load (%d)" % num - func = lambda: gdb.execute(do_test_load) - - self.measure.measure(func, num) + self.measure.measure(lambda: gdb.execute(do_test_load), num) do_test_unload = "call do_test_unload (%d)" % num gdb.execute(do_test_unload) @@ -59,9 +57,7 @@ class SolibLoadUnload1(perftest.TestCaseWithBasicMeasurements): gdb.execute(do_test_load) do_test_unload = "call do_test_unload (%d)" % num - func = lambda: gdb.execute(do_test_unload) - - self.measure.measure(func, num) + self.measure.measure(lambda: gdb.execute(do_test_unload), num) num = num / 2 iteration -= 1 diff --git a/gdb/testsuite/gdb.perf/template-breakpoints.py b/gdb/testsuite/gdb.perf/template-breakpoints.py index 82dc5b511a1..ac8b0668d26 100644 --- a/gdb/testsuite/gdb.perf/template-breakpoints.py +++ b/gdb/testsuite/gdb.perf/template-breakpoints.py @@ -32,5 +32,6 @@ class TemplateBreakpoints(perftest.TestCaseWithBasicMeasurements): def execute_test(self): for bpcount in range(1, 10): - tfunc = lambda bound_bpcount=bpcount: self._do_test(bound_bpcount) - self.measure.measure(tfunc, bpcount) + self.measure.measure( + lambda bound_bpcount=bpcount: self._do_test(bound_bpcount), bpcount + )