From 858a25abfa04ea992ac770bc14d0b03a3b9ba273 Mon Sep 17 00:00:00 2001 From: Robin Whittleton Date: Thu, 6 Jun 2024 12:22:20 +0200 Subject: [PATCH] Get pylint passing at 100% - a couple of branch removals - a couple of potentially unintialised variables --- se/commands/interactive_replace.py | 3 +-- se/commands/word_count.py | 4 +++- se/se_epub_lint.py | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/se/commands/interactive_replace.py b/se/commands/interactive_replace.py index eaf113f0..f54039aa 100644 --- a/se/commands/interactive_replace.py +++ b/se/commands/interactive_replace.py @@ -37,8 +37,7 @@ def _get_text_dimensions(text: str) -> Tuple[int, int]: else: line_length = line_length + 1 - if line_length > text_width: - text_width = line_length + text_width = max(text_width, line_length) return (text_height + 1, text_width + 1) diff --git a/se/commands/word_count.py b/se/commands/word_count.py index 78dd6335..233c92b9 100644 --- a/se/commands/word_count.py +++ b/se/commands/word_count.py @@ -75,6 +75,8 @@ def word_count(plain_output: bool) -> int: se.print_error(f"Couldn’t open file: [path][link=file://{filename}]{filename}[/][/].", plain_output=plain_output) return se.InvalidInputException.code + category = "" + if args.categorize: category = "se:short-story" if NOVELLA_MIN_WORD_COUNT <= total_word_count < NOVEL_MIN_WORD_COUNT: @@ -82,6 +84,6 @@ def word_count(plain_output: bool) -> int: elif total_word_count >= NOVEL_MIN_WORD_COUNT: category = "se:novel" - print(f"{total_word_count}\t{category if args.categorize else ''}") + print(f"{total_word_count}\t{category}") return 0 diff --git a/se/se_epub_lint.py b/se/se_epub_lint.py index 0ecdc42f..53738a6f 100644 --- a/se/se_epub_lint.py +++ b/se/se_epub_lint.py @@ -510,8 +510,7 @@ def __init__(self, code: str, text: str, message_type=se.MESSAGE_TYPE_WARNING, f for submessage in submessages: # Try to flatten leading indentation for indent in regex.findall(r"^\t+(?=<)", submessage, flags=regex.MULTILINE): - if len(indent) < smallest_indent: - smallest_indent = len(indent) + smallest_indent = min(smallest_indent, len(indent)) if smallest_indent == 1000: smallest_indent = 0 @@ -1505,6 +1504,7 @@ def _lint_special_file_checks(self, filename: Path, dom: se.easy_xml.EasyXmlTree for node in dom.xpath("/html/body/nav[contains(@epub:type, 'loi')]//li//a"): figure_ref = node.get_attr("href").split("#")[1] chapter_ref = regex.findall(r"(.*?)#.*", node.get_attr("href"))[0] + figure_img_alt = "" figcaption_text = "" loi_text = node.inner_text() file_dom = self.get_dom(self.content_path / "text" / chapter_ref)