From c663acc4ed8e7d2a9e4389a3e8f790d60a070a0c Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Thu, 18 Jun 2026 16:54:00 +0200 Subject: use format strings --- algorithms/algorithm.py | 1 - algorithms/input_kind.py | 2 +- algorithms/params.py | 6 +++--- algorithms/scripts/plot.py | 8 ++++---- algorithms/scripts/test.py | 6 +++--- 5 files changed, 11 insertions(+), 12 deletions(-) diff --git a/algorithms/algorithm.py b/algorithms/algorithm.py index 55d4929..ebbd559 100644 --- a/algorithms/algorithm.py +++ b/algorithms/algorithm.py @@ -14,7 +14,6 @@ class Algorithm: @staticmethod def gen_input(n, case=input_kind.InputKind.AVERAGE): - # raise NotImplementedError('input generation is not defined for a generic algorithm') return input_kind.gen_input_for_sorting(n, case) diff --git a/algorithms/input_kind.py b/algorithms/input_kind.py index b91d298..68a93d8 100644 --- a/algorithms/input_kind.py +++ b/algorithms/input_kind.py @@ -30,4 +30,4 @@ def gen_input_for_sorting(n, case=InputKind.AVERAGE): return _gen_input_from(sample(range(n), n)) if case is InputKind.WORST: return _gen_input_from(range(n - 1, -1, -1)) - raise NotImplementedError("invalid input kind: " + str(case)) + raise NotImplementedError(f"invalid input kind: {case}") diff --git a/algorithms/params.py b/algorithms/params.py index 818ca47..fb5af6f 100644 --- a/algorithms/params.py +++ b/algorithms/params.py @@ -24,7 +24,7 @@ class TimeUnits(Enum): return 1000.0 if self is TimeUnits.MICROSECONDS: return 1000000.0 - raise NotImplementedError("invalid time units: " + str(self)) + raise NotImplementedError(f"invalid time units: {self}") def __str__(self): return self.value @@ -109,10 +109,10 @@ class AlgorithmParameters: @staticmethod def _format_plot_ylabel(units): - return "Running time ({})".format(units) + return f"Running time ({units})" def _format_plot_title(self): - return "{}, {} case".format(self.algorithm.display_name, self.input_kind) + return f"{self.algorithm.display_name}, {self.input_kind} case" def _format_plot_suptitle(self): return self.algorithm.display_name diff --git a/algorithms/scripts/plot.py b/algorithms/scripts/plot.py index 25a87f7..61eeab1 100755 --- a/algorithms/scripts/plot.py +++ b/algorithms/scripts/plot.py @@ -40,7 +40,7 @@ def _parse_non_negative_integer(s): try: n = int(s) except ValueError: - raise argparse.ArgumentTypeError("must be a non-negative integer: " + str(s)) + raise argparse.ArgumentTypeError(f"must be a non-negative integer: {s}") if n < 0: raise argparse.ArgumentTypeError("must be a non-negative integer") return n @@ -50,7 +50,7 @@ def _parse_positive_integer(s): try: n = int(s) except ValueError: - raise argparse.ArgumentTypeError("must be a positive integer: " + str(s)) + raise argparse.ArgumentTypeError(f"must be a positive integer: {s}") if n < 1: raise argparse.ArgumentTypeError("must be a positive integer") return n @@ -60,11 +60,11 @@ def _parse_input_kind(s): try: return InputKind(s) except ValueError: - raise argparse.ArgumentTypeError("invalid input kind: " + str(s)) + raise argparse.ArgumentTypeError(f"invalid input kind: {s}") def _format_algorithm(codename): - return "* {}: {}".format(codename, registry.get(codename).display_name) + return "* {codename}: {registry.get(codename).display_name}" def _format_available_algorithms(): diff --git a/algorithms/scripts/test.py b/algorithms/scripts/test.py index 52acc34..7fd7c68 100755 --- a/algorithms/scripts/test.py +++ b/algorithms/scripts/test.py @@ -30,7 +30,7 @@ def _parse_non_negative_integer(s): try: n = int(s) except ValueError: - raise argparse.ArgumentTypeError("must be a non-negative integer: " + str(s)) + raise argparse.ArgumentTypeError(f"must be a non-negative integer: {s}") if n < 0: raise argparse.ArgumentTypeError("must be a non-negative integer") return n @@ -40,11 +40,11 @@ def _parse_input_kind(s): try: return InputKind(s) except ValueError: - raise argparse.ArgumentTypeError("invalid input kind: " + str(s)) + raise argparse.ArgumentTypeError(f"invalid input kind: {s}") def _format_algorithm(codename): - return "* {}: {}".format(codename, registry.get(codename).display_name) + return "* {codename}: {registry.get(codename).display_name}" def _format_available_algorithms(): -- cgit v1.3