From 1274de476d58a35098ade54ccc023efee4e8350c Mon Sep 17 00:00:00 2001 From: Martin Hoyer Date: Fri, 25 Oct 2024 16:21:40 +0200 Subject: [PATCH] Update pre-commit hooks, ruff rules --- .gitignore | 1 + .pre-commit-config.yaml | 4 ++-- configshell/node.py | 6 ++---- configshell/shell.py | 18 +++++++----------- pyproject.toml | 2 ++ 5 files changed, 14 insertions(+), 17 deletions(-) diff --git a/.gitignore b/.gitignore index ad46a87..75d3502 100644 --- a/.gitignore +++ b/.gitignore @@ -23,5 +23,6 @@ debian/tmp/ *.pyc rtslib-* venv/ +.venv/ .idea *egg-info/ diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 209c747..a0e101f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,12 +1,12 @@ repos: - repo: https://github.com/charliermarsh/ruff-pre-commit - rev: v0.6.4 + rev: v0.7.1 hooks: - id: ruff args: [--fix] - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.6.0 + rev: v5.0.0 hooks: - id: check-case-conflict - id: check-ast diff --git a/configshell/node.py b/configshell/node.py index fdf4de2..d057063 100644 --- a/configshell/node.py +++ b/configshell/node.py @@ -1243,10 +1243,8 @@ def ui_command_bookmarks(self, action, bookmark=None): if not self.shell.prefs['bookmarks']: bookmarks += "No bookmarks yet.\n" else: - for (bookmark, path) \ - in self.shell.prefs['bookmarks'].items(): - if len(bookmark) == 1: - bookmark += '\0' + for (_bookmark, path) in self.shell.prefs['bookmarks'].items(): + bookmark = _bookmark if len(_bookmark) != 1 else _bookmark + '\0' underline = ''.ljust(len(bookmark), '-') bookmarks += f"{bookmark}\n{underline}\n{path}\n\n" self.shell.con.epy_write(bookmarks) diff --git a/configshell/shell.py b/configshell/shell.py index bc9b6e1..304a4f1 100644 --- a/configshell/shell.py +++ b/configshell/shell.py @@ -401,12 +401,11 @@ def _complete_token_pparam(self, text, path, command, pparams, kparams): target = self._current_node.get_node(path) cmd_params, free_pparams, free_kparams = \ target.get_command_signature(command) - current_parameters = {} - for index in range(len(pparams)): - if index < len(cmd_params): - current_parameters[cmd_params[index]] = pparams[index] - for key, value in kparams.items(): - current_parameters[key] = value + current_parameters = { + cmd_params[index]: pparams[index] + for index in range(min(len(pparams), len(cmd_params))) + } + current_parameters.update(kparams) self._completion_help_topic = command completion_method = target.get_completion_method(command) self.log.debug(f"Command {command} accepts parameters {cmd_params}.") @@ -544,11 +543,8 @@ def _complete_token_kparam(self, text, path, command, pparams, kparams): self.log.debug(f"Completing '{current_value}' for kparam {keyword}") self._current_parameter = keyword - current_parameters = {} - for index in range(len(pparams)): - current_parameters[cmd_params[index]] = pparams[index] - for key, value in kparams.items(): - current_parameters[key] = value + current_parameters = {cmd_params[index]: pparams[index] for index in range(len(pparams))} + current_parameters.update(dict(kparams.items())) completion_method = target.get_completion_method(command) if completion_method: completions = completion_method( diff --git a/pyproject.toml b/pyproject.toml index ec37959..1056b99 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -88,6 +88,8 @@ ignore = [ "B904", # raise-without-from-inside-except "PLR09", # Too many branches/statements/arguments "S105", # Possible hardcoded password assigned + "S605", # TODO Starting a process with a shell + "S607", # TODO Starting a process with a partial executable path "RET505", # Unnecessary `else` after `return` statement "PLW2901", # TODO `for` loop variable overwritten by assignment target "UP031", # TODO Use format specifiers instead of percent format