Skip to content

Commit

Permalink
Address some of the ruff exceptions (miscellaneous) (#1756)
Browse files Browse the repository at this point in the history
* Address some of the ruff exceptions

* check failure

* add changes for PIE

* address RUF100

* Remove PLC1901

* Address RUF009

* Address S110
  • Loading branch information
shatakshiiii committed May 15, 2024
1 parent 935f583 commit dea8fd2
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 16 deletions.
4 changes: 0 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,6 @@ ignore = [
'PGH003', # Use specific rule codes when ignoring type issues
'PIE810', # [*] Call `startswith` once with a `tuple`
'PD011', # https://github.com/astral-sh/ruff/issues/2229
'PLC1901', # `self.fs_source == ""` can be simplified to `not self.fs_source` as an empty string is falsey
'PLR0911', # Too many return statements (8 > 6)
'PLR0912', # Too many branches (13 > 12)
'PLR0913', # Too many arguments to function call (7 > 5)
Expand Down Expand Up @@ -343,13 +342,10 @@ ignore = [
'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
'RUF009', # Do not perform function call `PresentableCliParameters` in dataclass defaults
'RUF012', # Mutable class attributes should be annotated with `typing.ClassVar`
'RUF100', # [*] Unused `noqa` directive (unused: `E731`)
'S101', # Use of `assert` detected
'S103', # `os.chmod` setting a permissive mask `0o777` on file or directory
'S108', # Probable insecure usage of temporary file or directory: "/tmp"
'S110', # `try`-`except`-`pass` detected, consider logging the exception
'S311', # Standard pseudo-random generators are not suitable for cryptographic purposes
'S602', # `subprocess` call with `shell=True` identified, security issue
'S603', # `subprocess` call: check for execution of untrusted input
Expand Down
2 changes: 1 addition & 1 deletion src/ansible_navigator/actions/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def get_color(word: str) -> int:
:param word: Keyword to match color.
:returns: Color value
"""
return next( # noqa: E731
return next(
(x[1] for x in RESULT_TO_COLOR if re.match(x[0], word)),
0,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from __future__ import annotations

from dataclasses import dataclass
from dataclasses import field
from typing import Any
from typing import ClassVar
from typing import NewType
Expand Down Expand Up @@ -82,7 +83,7 @@ class PresentableSettingsEntry(ContentBase[Any]):
"""A list of subcommands where this entry is available"""
version_added: str
"""The version this entry was added in"""
cli_parameters: PresentableCliParameters = PresentableCliParameters()
cli_parameters: PresentableCliParameters = field(default_factory=PresentableCliParameters)
"""The CLI parameters, long and short"""

@property
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class Internals:

ansible_configuration: AnsibleConfiguration = field(default_factory=AnsibleConfiguration)
action_packages: tuple[str] = ("ansible_navigator.actions",)
cache_path: Path = generate_cache_path(APP_NAME.replace("_", "-"))
cache_path: Path = generate_cache_path(APP_NAME.replace("_", "-")) # noqa: RUF009
collection_doc_cache: C | KeyValueStore = C.NOT_SET
initializing: bool = False
"""This is an initial run (app starting for the first time)."""
Expand Down
2 changes: 1 addition & 1 deletion src/ansible_navigator/tm_tokenize/reg.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@


_FLAGS = {
# (first_line, boundary) # noqa: E800
# (first_line, boundary)
(False, False): (
onigurumacffi.OnigSearchOption.NOT_END_STRING
| onigurumacffi.OnigSearchOption.NOT_BEGIN_STRING
Expand Down
2 changes: 1 addition & 1 deletion src/ansible_navigator/ui_framework/form_handler_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def populate(self, form_field: FieldText, active: int) -> None:
if self._ui_config.color is False:
text = (
f"[{option.text.capitalize()}]" if idx == active else option.text + " "
) # clear the [], for else # noqa: E501
) # clear the [], for else
else:
text = option.text
clp_text = CursesLinePart(len(option_code) + 1, text, color, decoration)
Expand Down
2 changes: 1 addition & 1 deletion src/ansible_navigator/utils/dict_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def in_place_list_replace(left: Mergeable, right: Mergeable) -> Mergeable:
"""
key = None
try:
if left is None or isinstance(left, str | int | float | bool): # noqa: SIM114
if left is None or isinstance(left, str | int | float | bool):
# Border case for first run or if a is a primitive
left = right
elif isinstance(left, tuple | list):
Expand Down
6 changes: 3 additions & 3 deletions src/ansible_navigator/utils/serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@
try:
from yaml import CSafeDumper as SafeDumper
except ImportError:
from yaml import SafeDumper # type: ignore # noqa: F401
from yaml import SafeDumper # type: ignore

try:
from yaml import CLoader as Loader
from yaml import CSafeLoader as SafeLoader
except ImportError:
from yaml import Loader # type: ignore # noqa: F401
from yaml import SafeLoader # type: ignore # noqa: F401
from yaml import Loader # type: ignore
from yaml import SafeLoader # type: ignore


def serialize(
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/test_circular_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
* https://github.com/pytest-dev/pytest/blob/d18c75b/testing/test_meta.py
* https://twitter.com/codewithanthony/status/1229445110510735361
* https://github.com/aio-libs/aiohttp/blob/master/tests/test_circular_imports.py
""" # noqa: E501
"""
from __future__ import annotations

import os
import pkgutil
import subprocess # noqa: S404 Required due to the nature of this test
import subprocess # Required due to the nature of this test
import sys

from collections.abc import Generator
Expand Down Expand Up @@ -108,4 +108,4 @@ def test_no_warnings(import_path: str) -> None:
f"import {import_path!s}",
)

subprocess.check_call(imp_cmd) # noqa: S603 Input is trusted, generated above, not external
subprocess.check_call(imp_cmd) # Input is trusted, generated above, not external

0 comments on commit dea8fd2

Please sign in to comment.