From b47c9b6e9126f890dbcc04c249ae6124172327d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Sun, 3 Aug 2025 09:50:13 +0200 Subject: [PATCH] [output] use f-strings for concatenations (#7671) --- gallery_dl/output.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/gallery_dl/output.py b/gallery_dl/output.py index 6d82f41f..519a8f4c 100644 --- a/gallery_dl/output.py +++ b/gallery_dl/output.py @@ -165,9 +165,9 @@ class Formatter(logging.Formatter): if record.exc_info and not record.exc_text: record.exc_text = self.formatException(record.exc_info) if record.exc_text: - msg = msg + "\n" + record.exc_text + msg = f"{msg}\n{record.exc_text}" if record.stack_info: - msg = msg + "\n" + record.stack_info + msg = f"{msg}\n{record.stack_info}" return msg @@ -372,10 +372,10 @@ class NullOutput(): class PipeOutput(NullOutput): def skip(self, path): - stdout_write(CHAR_SKIP + path + "\n") + stdout_write(f"{CHAR_SKIP}{path}\n") def success(self, path): - stdout_write(path + "\n") + stdout_write(f"{path}\n") class TerminalOutput(): @@ -390,13 +390,13 @@ class TerminalOutput(): self.shorten = util.identity def start(self, path): - stdout_write_flush(self.shorten(" " + path)) + stdout_write_flush(self.shorten(f" {path}")) def skip(self, path): - stdout_write(self.shorten(CHAR_SKIP + path) + "\n") + stdout_write(f"{self.shorten(CHAR_SKIP + path)}\n") def success(self, path): - stdout_write("\r" + self.shorten(CHAR_SUCCESS + path) + "\n") + stdout_write(f"\r{self.shorten(CHAR_SUCCESS + path)}\n") def progress(self, bytes_total, bytes_downloaded, bytes_per_second): bdl = util.format_value(bytes_downloaded) @@ -424,10 +424,10 @@ class ColorOutput(TerminalOutput): stdout_write_flush(self.shorten(path)) def skip(self, path): - stdout_write(self.color_skip + self.shorten(path) + "\033[0m\n") + stdout_write(f"{self.color_skip}{self.shorten(path)}\x1b[0m\n") def success(self, path): - stdout_write(self.color_success + self.shorten(path) + "\033[0m\n") + stdout_write(f"{self.color_success}{self.shorten(path)}\x1b[0m\n") class CustomOutput(): @@ -503,7 +503,7 @@ def shorten_string(txt, limit, sep="…"): if len(txt) <= limit: return txt limit -= len(sep) - return txt[:limit // 2] + sep + txt[-((limit+1) // 2):] + return f"{txt[:limit // 2]}{sep}{txt[-((limit+1) // 2):]}" def shorten_string_eaw(txt, limit, sep="…", cache=EAWCache()): @@ -518,7 +518,7 @@ def shorten_string_eaw(txt, limit, sep="…", cache=EAWCache()): limit -= len(sep) if text_width == len(txt): # all characters have a width of 1 - return txt[:limit // 2] + sep + txt[-((limit+1) // 2):] + return f"{txt[:limit // 2]}{sep}{txt[-((limit+1) // 2):]}" # wide characters left = 0 @@ -537,4 +537,4 @@ def shorten_string_eaw(txt, limit, sep="…", cache=EAWCache()): break right -= 1 - return txt[:left] + sep + txt[right+1:] + return f"{txt[:left]}{sep}{txt[right+1:]}"