From fdf572940e912e612a6be0b14a30b353d68a3a03 Mon Sep 17 00:00:00 2001 From: Robert Grimm Date: Thu, 10 Oct 2024 23:48:02 -0400 Subject: [PATCH] fix minor code quality issues --- prettypretty/grid.py | 3 ++- prettypretty/plot.py | 10 +++++----- prettypretty/terminal.py | 2 +- prettypretty/viz3d.py | 6 +++--- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/prettypretty/grid.py b/prettypretty/grid.py index d5723ba..c9d27af 100644 --- a/prettypretty/grid.py +++ b/prettypretty/grid.py @@ -249,7 +249,8 @@ def write_hires_slice( ) -> None: frame = FramedBoxes(term, 32, min_width=1) label = '/'.join( - f'{l.upper()}={level}' if l == hold else l.upper() for l in ('r', 'g', 'b') + f'{axis.upper()}={level}' if axis == hold else axis.upper() + for axis in ('r', 'g', 'b') ) frame.top( ('Downsampled ' if eight_bit_only else '') diff --git a/prettypretty/plot.py b/prettypretty/plot.py index ff87884..5438800 100644 --- a/prettypretty/plot.py +++ b/prettypretty/plot.py @@ -23,10 +23,10 @@ close_enough, Color, ColorSpace, - gamut, # pyright: ignore [reportMissingModuleSource] spectrum, # pyright: ignore [reportMissingModuleSource] trans, # pyright: ignore [reportMissingModuleSource] ) +from .color.gamut import GamutTraversalStep # pyright: ignore [reportMissingModuleSource] from .theme import current_translator @@ -267,7 +267,7 @@ def trace_spectrum( all_colors: list[list[str]] = [] for step in self._illuminated_observer.visual_gamut(spectrum.ONE_NANOMETER): - if isinstance(step, gamut.GamutTraversalStep.MoveTo): + if isinstance(step, GamutTraversalStep.MoveTo): lines2d.append([]) all_colors.append([]) if locus_only and len(lines2d) > 1: @@ -329,7 +329,7 @@ def trace_gamut(self, space: ColorSpace, axes: Any) -> None: all_points.append(pt) all_colors.append(hex_format) - if isinstance(step, gamut.GamutTraversalStep.CloseWith): + if isinstance(step, GamutTraversalStep.CloseWith): break assert close_enough(all_points[0][0], all_points[-1][0]) @@ -528,7 +528,7 @@ def create_figure( light_axes.set_ylim(0, 1) light_axes.margins(x=0.02, tight=True) - if all(l is not None for l in self._bar_label): + if all(label is not None for label in self._bar_label): lry_offset = 0.015 light_axes.xaxis.set_major_locator( FixedLocator([*range(len(self._bar_label))]) @@ -635,7 +635,7 @@ def main() -> None: if options.input is not None: with open(options.input, mode="r", encoding="utf8") as file: - for color in [Color.parse(l) for l in file.readlines() if l.strip()]: + for color in [Color.parse(line) for line in file.readlines() if line.strip()]: plotter.add(cname, color, marker=marker) for color in [Color.parse(c) for c in cast(list[str], options.colors) or []]: diff --git a/prettypretty/terminal.py b/prettypretty/terminal.py index 0a6838b..1fa20b6 100644 --- a/prettypretty/terminal.py +++ b/prettypretty/terminal.py @@ -535,7 +535,7 @@ def write_paragraph(self, text: str) -> Self: being convenient to read. Finally, it writes the resulting text to this terminal's output. This method does not flush the output. """ - lines = [l.strip() for l in text.splitlines()] + lines = [line.strip() for line in text.splitlines()] start = stop = 0 while True: diff --git a/prettypretty/viz3d.py b/prettypretty/viz3d.py index addf00a..565b224 100644 --- a/prettypretty/viz3d.py +++ b/prettypretty/viz3d.py @@ -418,7 +418,7 @@ def generate_faces(self) -> None: msg = "" if trace_enabled: - msg = f"capstones " + msg = "capstones " for edge in [(r, s), (t, s), (r, t), (u, w), (v, w), (u, v)]: assert edge[0] <= edge[1] @@ -656,7 +656,7 @@ def render(*, filename: str, label: str, is_ok: bool) -> None: sys.exit(1) if options.planar_gamut and gamut is None: - log(f"The --planar-gamut option requires the --gamut option") + log("The --planar-gamut option requires the --gamut option") sys.exit(1) # -------------------------------------------------------------------------- Stride @@ -664,7 +664,7 @@ def render(*, filename: str, label: str, is_ok: bool) -> None: if options.stride: try: stride = int(options.stride) - except: + except ValueError: log(f"stride {stride} is not an integer") sys.exit(1) if not (1 <= stride <= 20):