From 75458f8e642a42b3ffbfbe9e69c6d50b3be76629 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edouard=20Choini=C3=A8re?= <27212526+echoix@users.noreply.github.com> Date: Thu, 19 Sep 2024 17:05:49 -0400 Subject: [PATCH] style: Call `startswith` or `endswith` once with a `tuple` (PIE810) (#4348) style: Call `startswith` once with a `tuple` (PIE810) Ruff rule: https://docs.astral.sh/ruff/rules/multiple-starts-ends-with/ --- gui/wxpython/core/toolboxes.py | 2 +- gui/wxpython/psmap/instructions.py | 6 +----- lib/init/grass.py | 4 +--- man/build_class_graphical.py | 4 +--- pyproject.toml | 1 - utils/generate_release_notes.py | 2 +- utils/gitlog2changelog.py | 2 +- 7 files changed, 6 insertions(+), 15 deletions(-) diff --git a/gui/wxpython/core/toolboxes.py b/gui/wxpython/core/toolboxes.py index 441898fa8f6..ae6b1b6a0a6 100644 --- a/gui/wxpython/core/toolboxes.py +++ b/gui/wxpython/core/toolboxes.py @@ -855,7 +855,7 @@ def module_test(): someDiff = False for line in result: - if line.startswith("+") or line.startswith("-"): + if line.startswith(("+", "-")): sys.stdout.write(line) someDiff = True if someDiff: diff --git a/gui/wxpython/psmap/instructions.py b/gui/wxpython/psmap/instructions.py index 2ae68a91069..8a535b96704 100644 --- a/gui/wxpython/psmap/instructions.py +++ b/gui/wxpython/psmap/instructions.py @@ -1936,11 +1936,7 @@ def Read(self, instruction, text, **kwargs): instr = {} for line in text: - if ( - line.startswith("vpoints") - or line.startswith("vlines") - or line.startswith("vareas") - ): + if line.startswith(("vpoints", "vlines", "vareas")): # subtype if line.startswith("vpoints"): subType = "points" diff --git a/lib/init/grass.py b/lib/init/grass.py index 28537f957b1..30c0a1a68ba 100755 --- a/lib/init/grass.py +++ b/lib/init/grass.py @@ -1057,9 +1057,7 @@ def load_env(grass_env_file): v = v.strip('"') # we'll keep expand=True to expand $var's inside "value" because # they are within double quotes - elif ( - v.startswith("'") or v.endswith("'") or v.startswith('"') or v.endswith('"') - ): + elif v.startswith(("'", '"')) or v.endswith(("'", '"')): # here, let's try to ignore unmatching single/double quotes, which # might be a multi-line variable or just a user error debug("Ignoring multi-line environmental variable {0}".format(k)) diff --git a/man/build_class_graphical.py b/man/build_class_graphical.py index 955f5c2a63e..35b2a731cfe 100644 --- a/man/build_class_graphical.py +++ b/man/build_class_graphical.py @@ -102,9 +102,7 @@ def starts_with_module(string, module) -> bool: # module = module.replace('wxGUI.', 'g.gui.') # TODO: matches g.mapsets images for g.mapset and d.rast.num for d.rast return bool( - string.startswith(module.replace(".", "_")) - or string.startswith(module.replace(".", "")) - or string.startswith(module) + string.startswith((module.replace(".", "_"), module.replace(".", ""), module)) ) diff --git a/pyproject.toml b/pyproject.toml index 6689d6375eb..649e309a73f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -154,7 +154,6 @@ ignore = [ "PERF403", # manual-dict-comprehension "PIE794", # duplicate-class-field-definition "PIE808", # unnecessary-range-start - "PIE810", # multiple-starts-ends-with "PLC0415", # import-outside-top-level "PLC1901", # compare-to-empty-string "PLC2701", # import-private-name diff --git a/utils/generate_release_notes.py b/utils/generate_release_notes.py index 66aa4ced08c..c8a22b01d86 100755 --- a/utils/generate_release_notes.py +++ b/utils/generate_release_notes.py @@ -227,7 +227,7 @@ def notes_from_gh_api(start_tag, end_tag, branch, categories, exclude): raw_changes = lines[start_whats_changed + 1 : end_whats_changed] changes = [] for change in raw_changes: - if change.startswith("* ") or change.startswith("- "): + if change.startswith(("* ", "- ")): changes.append(change[2:]) else: changes.append(change) diff --git a/utils/gitlog2changelog.py b/utils/gitlog2changelog.py index 758b142196b..43aedcfb491 100755 --- a/utils/gitlog2changelog.py +++ b/utils/gitlog2changelog.py @@ -79,7 +79,7 @@ except Exception as e: print(f"Could not parse dateList = '{line}'. Error: {e!s}") # The Fossil-IDs are ignored: - elif line.startswith(" Fossil-ID:") or line.startswith(" [[SVN:"): + elif line.startswith((" Fossil-ID:", " [[SVN:")): continue # The svn-id lines are ignored elif " git-svn-id:" in line: