Skip to content

Commit

Permalink
Address ruff C (ansible#1782)
Browse files Browse the repository at this point in the history
* Address ruff C

* Address ruff C414

* Address ruff C409
  • Loading branch information
shatakshiiii authored May 30, 2024
1 parent 492eb1e commit d11d09b
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 39 deletions.
3 changes: 0 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,6 @@ ignore = [
'ARG004', # Unused static method argument: `config`
'ARG005', # Unused lambda argument: `args`
'B006', # Do not use mutable data structures for argument defaults
'C408', # [*] Unnecessary `tuple` call (rewrite as a literal)
'C409', # [*] Unnecessary `list` literal passed to `tuple()` (rewrite as a `tuple` literal)
'C414', # [*] Unnecessary `list` call within `sorted()`
'C901', # `_params_row_for_entry` is too complex (11 > 10)
'D100', # Missing docstring in public module
'D101', # Missing docstring in public class
Expand Down
4 changes: 2 additions & 2 deletions src/ansible_navigator/actions/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ def _parse(self, output: str) -> None:
self._logger.error("%s %s", error["path"], error["error"])

self._collections = sorted(
list(parsed["collections"].values()),
parsed["collections"].values(),
key=lambda i: i["known_as"],
)
volume_mounts = self.app.args.execution_environment_volume_mounts
Expand All @@ -559,7 +559,7 @@ def _parse(self, output: str) -> None:
tmp_list.append(str(dest_path))
dest_volume_mounts = tuple(tmp_list)
else:
dest_volume_mounts = tuple()
dest_volume_mounts = ()

for collection in self._collections:
collection["__name"] = collection["known_as"]
Expand Down
6 changes: 3 additions & 3 deletions src/ansible_navigator/ui_framework/menu_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@ def _menu(
for idx, column_width in enumerate(adjusted_column_widths):
col_starts.append(column_width + col_starts[idx])

menu_layout = tuple([col_starts, cols, adjusted_column_widths])
menu_layout = (col_starts, cols, adjusted_column_widths)
header = self._menu_header_line(menu_layout)

menu_layout = tuple([col_starts, cols, adjusted_column_widths, header])
menu_layout = (col_starts, cols, adjusted_column_widths, header) # type: ignore
menu_lines = self._menu_lines(dicts, menu_layout, indices)
return CursesLines(tuple([header])), menu_lines
return CursesLines((header,)), menu_lines

def _menu_header_line(self, menu_layout: Any) -> CursesLine:
"""Generate the menu header line.
Expand Down
4 changes: 2 additions & 2 deletions src/ansible_navigator/ui_framework/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def __init__(
self._kegexes = kegexes
self._logger = logging.getLogger(__name__)
self._menu_filter: Pattern[str] | None = None
self._menu_indices: tuple[int, ...] = tuple()
self._menu_indices: tuple[int, ...] = ()

self._progress_bar_width = progress_bar_width
self._status_width = status_width
Expand Down Expand Up @@ -426,7 +426,7 @@ def _display(
:param count: The count to show
:returns: the key pressed
"""
heading = heading or CursesLines(tuple())
heading = heading or CursesLines(())
heading_len = len(heading)
footer = self._footer({**STANDARD_KEYS, **key_dict, **END_KEYS})
footer_at = self._screen_height - 1 # screen is 0 based index
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def config_path(self) -> bool:
return True

self.content = move_to_path(
behaviors=tuple(),
behaviors=(),
content=self.content,
new_path=new_path,
old_path=old_path,
Expand All @@ -73,7 +73,7 @@ def documentation(self) -> bool:
return exists

self.content = move_to_path(
behaviors=tuple(),
behaviors=(),
content=self.content,
new_path=new_path,
old_path=old_path,
Expand Down Expand Up @@ -101,7 +101,7 @@ def playbook_path(self) -> bool:
return True

self.content = move_to_path(
behaviors=tuple(),
behaviors=(),
content=self.content,
new_path=new_path,
old_path=old_path,
Expand All @@ -122,7 +122,7 @@ def help_builder(self) -> bool:
return exists

self.content = move_to_path(
behaviors=tuple(),
behaviors=(),
content=self.content,
new_path=new_path,
old_path=old_path,
Expand All @@ -143,7 +143,7 @@ def help_config(self) -> bool:
return exists

self.content = move_to_path(
behaviors=tuple(),
behaviors=(),
content=self.content,
new_path=new_path,
old_path=old_path,
Expand All @@ -164,7 +164,7 @@ def help_doc(self) -> bool:
return exists

self.content = move_to_path(
behaviors=tuple(),
behaviors=(),
content=self.content,
new_path=new_path,
old_path=old_path,
Expand All @@ -185,7 +185,7 @@ def help_inventory(self) -> bool:
return exists

self.content = move_to_path(
behaviors=tuple(),
behaviors=(),
content=self.content,
new_path=new_path,
old_path=old_path,
Expand All @@ -206,7 +206,7 @@ def help_playbook(self) -> bool:
return exists

self.content = move_to_path(
behaviors=tuple(),
behaviors=(),
content=self.content,
new_path=new_path,
old_path=old_path,
Expand Down Expand Up @@ -261,7 +261,7 @@ def playbook_artifact(self) -> bool:
new_value = value.replace("ts_utc", "time_stamp")

self.content = place_at_path(
behaviors=tuple(),
behaviors=(),
content=self.content,
path=path,
value=new_value,
Expand All @@ -282,7 +282,7 @@ def pull_policy(self) -> bool:
return exists

self.content = move_to_path(
behaviors=tuple(),
behaviors=(),
content=self.content,
new_path=new_path,
old_path=old_path,
Expand Down
26 changes: 13 additions & 13 deletions tests/unit/utils/test_dot_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def __str__(self) -> str:
),
Scenario(
name="12",
behaviors=tuple(),
behaviors=(),
comment="deep change str",
content={"a": {"b": {"c": {"d": {"e": "f"}}}}},
path="a.b.c.d.e",
Expand All @@ -214,7 +214,7 @@ def __str__(self) -> str:
),
Scenario(
name="13",
behaviors=tuple(),
behaviors=(),
comment="deep dict replace",
content={"a": {"b": {"c": {"d": {"e": "f"}}}}},
path="a.b.c.d",
Expand All @@ -223,7 +223,7 @@ def __str__(self) -> str:
),
Scenario(
name="14",
behaviors=tuple(),
behaviors=(),
comment="deep dict placement",
path="root.dict.aa.bb",
expected={"root": {"dict": {"a": "b", "aa": {"bb": True}}, "list": [1, 2, 3]}},
Expand Down Expand Up @@ -266,39 +266,39 @@ def test_place_at_path_success(scenario: Scenario) -> None:
),
Scenario(
name="2",
behaviors=tuple(),
behaviors=(),
comment="Test dict_dict",
path="root.dict",
expected=None,
value={"c": "d"},
),
Scenario(
name="3",
behaviors=tuple(),
behaviors=(),
comment="Test list_list behavior",
path="root.list",
expected=None,
value=[4, 5, 6],
),
Scenario(
name="4",
behaviors=tuple(),
behaviors=(),
comment="Test list behavior",
path="root.list",
expected=None,
value=True,
),
Scenario(
name="5",
behaviors=tuple(),
behaviors=(),
comment="Test mass replace",
path="",
expected=None,
value={"bool": True},
),
Scenario(
name="6",
behaviors=tuple(),
behaviors=(),
comment="Test mass replace",
path="",
expected=None,
Expand All @@ -325,39 +325,39 @@ def test_place_at_path_raises(scenario: Scenario) -> None:
scenarios_move = (
Scenario(
name="0",
behaviors=tuple(),
behaviors=(),
comment="Test list move",
path="root.list",
new_path="root.list_moved",
expected={"root": {"dict": {"a": "b"}, "list_moved": [1, 2, 3]}},
),
Scenario(
name="1",
behaviors=tuple(),
behaviors=(),
comment="Test dict move",
path="root.dict",
new_path="root.dict_moved",
expected={"root": {"dict_moved": {"a": "b"}, "list": [1, 2, 3]}},
),
Scenario(
name="2",
behaviors=tuple(),
behaviors=(),
comment="Test dict move and cleanup",
path="root.dict.a",
new_path="root.dict.aa",
expected={"root": {"dict": {"aa": "b"}, "list": [1, 2, 3]}},
),
Scenario(
name="3",
behaviors=tuple(),
behaviors=(),
comment="Test move root nested",
path="root",
new_path="r0.r1.r2.r3",
expected={"r0": {"r1": {"r2": {"r3": {"dict": {"a": "b"}, "list": [1, 2, 3]}}}}},
),
Scenario(
name="4",
behaviors=tuple(),
behaviors=(),
comment="Test move same ",
path="root.dict",
new_path="root.dict",
Expand Down
12 changes: 6 additions & 6 deletions tests/unit/utils/test_key_value_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def test_kvs_iterkeys(kvs: KeyValueStore) -> None:

# Does it have all the keys we expect? (sorted because dicts don't care
# about order)
assert sorted(list(kvs.iterkeys())) == ["apple", "banana", "grape", "strawberry"]
assert sorted(kvs.iterkeys()) == ["apple", "banana", "grape", "strawberry"]


def test_kvs_itervalues(kvs: KeyValueStore) -> None:
Expand All @@ -52,7 +52,7 @@ def test_kvs_itervalues(kvs: KeyValueStore) -> None:

# Does it have all the values we expect? (sorted because dicts don't care
# about order)
assert sorted(list(kvs.itervalues())) == ["green", "red", "red", "yellow"]
assert sorted(kvs.itervalues()) == ["green", "red", "red", "yellow"]


def test_kvs_iteritems(kvs: KeyValueStore) -> None:
Expand All @@ -65,7 +65,7 @@ def test_kvs_iteritems(kvs: KeyValueStore) -> None:

# Does it have all the items we expect? (sorted because dicts don't care
# about order)
assert sorted(list(kvs.iteritems())) == [
assert sorted(kvs.iteritems()) == [
("apple", "red"),
("banana", "yellow"),
("grape", "green"),
Expand All @@ -87,7 +87,7 @@ def test_kvs_keys(kvs: KeyValueStore) -> None:
assert "banana" in keys
assert "foo" not in keys
assert len(keys) == len(kvs)
assert sorted(list(keys)) == ["apple", "banana", "grape", "strawberry"]
assert sorted(keys) == ["apple", "banana", "grape", "strawberry"]


def test_kvs_values(kvs: KeyValueStore) -> None:
Expand All @@ -101,7 +101,7 @@ def test_kvs_values(kvs: KeyValueStore) -> None:
assert "red" in values
assert "blue" not in values
assert len(values) == len(kvs)
assert sorted(list(values)) == ["green", "red", "red", "yellow"]
assert sorted(values) == ["green", "red", "red", "yellow"]


def test_kvs_items(kvs: KeyValueStore) -> None:
Expand All @@ -115,7 +115,7 @@ def test_kvs_items(kvs: KeyValueStore) -> None:
assert ("banana", "yellow") in items
assert ("banana", "blue") not in items
assert len(items) == len(kvs)
assert sorted(list(kvs.items())) == [
assert sorted(kvs.items()) == [
("apple", "red"),
("banana", "yellow"),
("grape", "green"),
Expand Down

0 comments on commit d11d09b

Please sign in to comment.