From 24742a79abfed64244e94ad91db9d43c70e0d014 Mon Sep 17 00:00:00 2001 From: Shatakshi Mishra Date: Mon, 13 May 2024 15:05:41 +0530 Subject: [PATCH] Address ruff `RET` (#1757) --- pyproject.toml | 2 -- src/ansible_navigator/actions/collections.py | 4 ++-- src/ansible_navigator/actions/config.py | 8 ++++---- src/ansible_navigator/actions/open_file.py | 8 ++++---- src/ansible_navigator/actions/write_file.py | 6 +++--- tests/unit/configuration_subsystem/test_invalid_params.py | 2 +- tests/unit/logger/test_append.py | 2 +- tests/unit/logger/test_time_zone.py | 2 +- 8 files changed, 16 insertions(+), 18 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index e7f9e6354..5037b0c10 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -353,8 +353,6 @@ ignore = [ 'PYI034', # `__enter__` methods in classes like `TmuxSession` usually return `self` at runtime 'PYI036', # The first argument in `__exit__` should be annotated with `object` or `type[BaseException] | None` 'PYI041', # Use `float` instead of `int | float` - 'RET501', # [*] Do not explicitly `return None` in function if it is the only possible return value - 'RET503', # [*] Missing explicit `return` at the end of function able to return non-`None` value 'RET504', # Unnecessary variable assignment before `return` statement 'RET505', # Unnecessary `else` after `return` statement 'RUF005', # [*] Consider `[self._name, *shlex.split(self._interaction.action.match.groupdict()["params"] or "")]` instead of concatenation diff --git a/src/ansible_navigator/actions/collections.py b/src/ansible_navigator/actions/collections.py index c3c51c48d..73f13cb60 100644 --- a/src/ansible_navigator/actions/collections.py +++ b/src/ansible_navigator/actions/collections.py @@ -524,7 +524,7 @@ def _parse(self, output: str) -> None: self._logger.error("Unable to extract collection json from stdout") self._logger.debug("error json loading output: '%s'", str(exc)) self._logger.debug(output) - return None + return for error in parsed["errors"]: self._logger.error("%s %s", error["path"], error["error"]) @@ -593,7 +593,7 @@ def _parse(self, output: str) -> None: error += parsed["collection_scan_paths"] self._logger.warning(error) - return None + return def _get_collection_plugins_details( self, selected_collection: dict[str, Any] diff --git a/src/ansible_navigator/actions/config.py b/src/ansible_navigator/actions/config.py index 690ad2b1d..1fd904fe5 100644 --- a/src/ansible_navigator/actions/config.py +++ b/src/ansible_navigator/actions/config.py @@ -318,7 +318,7 @@ def _parse_and_merge(self, list_output: str, dump_output: str) -> None: self._logger.debug("yaml loading list output succeeded") except yaml.YAMLError as exc: self._logger.debug("error yaml loading list output: '%s'", str(exc)) - return None + return regex = re.compile(r"^(?P\S+)\((?P.*)\)\s=\s(?P.*)$") for line in dump_output.splitlines(): @@ -351,10 +351,10 @@ def _parse_and_merge(self, list_output: str, dump_output: str) -> None: parsed[variable]["current_value"] = current except KeyError: self._logger.error("variable '%s' not found in list output") - return None + return else: self._logger.error("Unparsable dump entry: %s", line) - return None + return for key, value in parsed.items(): value["option"] = key @@ -368,4 +368,4 @@ def _parse_and_merge(self, list_output: str, dump_output: str) -> None: self._config = list(parsed.values()) self._logger.debug("parsed and merged list and dump successfully") - return None + return diff --git a/src/ansible_navigator/actions/open_file.py b/src/ansible_navigator/actions/open_file.py index 24af488f6..1d7c36bc3 100644 --- a/src/ansible_navigator/actions/open_file.py +++ b/src/ansible_navigator/actions/open_file.py @@ -178,7 +178,7 @@ def run(self, interaction: Interaction, app: AppPublic) -> None: editor_console=editor_console, editor_command=editor_command, ) - return None + return temp_file_name = self._persist_content(content=requested, content_format=content_format) temp_line_number = 0 @@ -188,7 +188,7 @@ def run(self, interaction: Interaction, app: AppPublic) -> None: editor_console=editor_console, editor_command=editor_command, ) - return None + return if interaction.content: content = interaction.content.showing @@ -199,7 +199,7 @@ def run(self, interaction: Interaction, app: AppPublic) -> None: serialization_format=serialization_format, ) else: - return None + return content_file_name = self._persist_content(content=content, content_format=content_format) content_line_number = 0 @@ -209,4 +209,4 @@ def run(self, interaction: Interaction, app: AppPublic) -> None: editor_console=editor_console, editor_command=editor_command, ) - return None + return diff --git a/src/ansible_navigator/actions/write_file.py b/src/ansible_navigator/actions/write_file.py index 9da080a94..fe2868b9a 100644 --- a/src/ansible_navigator/actions/write_file.py +++ b/src/ansible_navigator/actions/write_file.py @@ -47,7 +47,7 @@ def run(self, interaction: Interaction, app: AppPublic) -> None: "Append operation failed because %s does not exist, force with !", filename, ) - return None + return file_mode = "a" else: if os.path.exists(filename) and not match["force"]: @@ -55,7 +55,7 @@ def run(self, interaction: Interaction, app: AppPublic) -> None: "Write operation failed because %s exists, force with !", filename, ) - return None + return file_mode = "w" if interaction.content: @@ -102,4 +102,4 @@ def run(self, interaction: Interaction, app: AppPublic) -> None: serialization_format=SerializationFormat.JSON, ) self._logger.info("Wrote to '%s' with mode '%s' as '%s'", filename, file_mode, write_as) - return None + return diff --git a/tests/unit/configuration_subsystem/test_invalid_params.py b/tests/unit/configuration_subsystem/test_invalid_params.py index bed7d5a51..7ef456c72 100644 --- a/tests/unit/configuration_subsystem/test_invalid_params.py +++ b/tests/unit/configuration_subsystem/test_invalid_params.py @@ -98,7 +98,7 @@ def local_which(*_args: Any, **_kwargs: dict[str, Any]) -> None: :param _kwargs: kwargs :returns: no container engine """ - return None + return monkeypatch.setattr("shutil.which", local_which) response = generate_config() diff --git a/tests/unit/logger/test_append.py b/tests/unit/logger/test_append.py index 9cbb9856d..2429ca09a 100644 --- a/tests/unit/logger/test_append.py +++ b/tests/unit/logger/test_append.py @@ -69,7 +69,7 @@ def return_none(*_args: Any, **_kwargs: dict[str, Any]) -> None: :param _kwargs: Keyword arguments :returns: Nothing """ - return None + return new_session_msg = "New ansible-navigator instance" log_file = tmp_path / "ansible-navigator.log" diff --git a/tests/unit/logger/test_time_zone.py b/tests/unit/logger/test_time_zone.py index 3abba9d93..c04e225ee 100644 --- a/tests/unit/logger/test_time_zone.py +++ b/tests/unit/logger/test_time_zone.py @@ -90,7 +90,7 @@ def return_none(*_args: Any, **_kwargs: dict[str, Any]) -> None: :param _kwargs: Keyword arguments :returns: Nothing """ - return None + return log_file = tmp_path / "ansible-navigator.log" args = data.args(log_file=log_file)