diff --git a/pyproject.toml b/pyproject.toml index bbc3df673..828c9d8cf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -110,7 +110,6 @@ line-length = 100 builtins = ["__"] select = ["ALL"] ignore = [ - 'A003', # Class attribute `repr` is shadowing a python builtin 'ANN001', # Missing type annotation for function argument `output` 'ANN002', # Missing type annotation for `*args` 'ANN003', # Missing type annotation for `**kwargs` diff --git a/src/ansible_navigator/actions/collections.py b/src/ansible_navigator/actions/collections.py index 2ec3143d7..c0986d77f 100644 --- a/src/ansible_navigator/actions/collections.py +++ b/src/ansible_navigator/actions/collections.py @@ -292,7 +292,7 @@ def _build_collection_content_menu(self): :returns: The plugin menu definition """ - self._collection_cache.open() + self._collection_cache.open_() selected_collection = self._collections[self.steps.current.index] collection_name = f"__{selected_collection['known_as']}" collection_contents = [] @@ -655,7 +655,7 @@ def _parse_collection_info_stdout(self) -> dict: roles_exclude_keys = ["readme"] self._collection_cache = cast(KeyValueStore, self._collection_cache) - self._collection_cache.open() + self._collection_cache.open_() for collection in self._collections: plugins_details = self._get_collection_plugins_details(collection) diff --git a/src/ansible_navigator/content_defs.py b/src/ansible_navigator/content_defs.py index 708bd8372..aa34b2258 100644 --- a/src/ansible_navigator/content_defs.py +++ b/src/ansible_navigator/content_defs.py @@ -33,13 +33,6 @@ class SerializationFormat(Enum): YAML = "YAML" JSON = "JSON" - def repr(self) -> str: - """Return a string representation. - - :return: A string - """ - return self.value - @dataclass class ContentBase(Generic[T]): diff --git a/src/ansible_navigator/data/image_introspect.py b/src/ansible_navigator/data/image_introspect.py index 8d9d70154..e13dc3769 100644 --- a/src/ansible_navigator/data/image_introspect.py +++ b/src/ansible_navigator/data/image_introspect.py @@ -21,7 +21,7 @@ class Command(SimpleNamespace): """Abstraction for a details about a shell command.""" - id: str + id_: str command: str parse: Callable stdout: str = "" @@ -209,7 +209,7 @@ def commands(self): command = "ansible-galaxy collection list" return [ Command( - id="ansible_collections", + id_="ansible_collections", command=command, parse=self.parse, ), @@ -241,7 +241,7 @@ def commands(self) -> list[Command]: :returns: The defined command """ - return [Command(id="ansible_version", command="ansible --version", parse=self.parse)] + return [Command(id_="ansible_version", command="ansible --version", parse=self.parse)] @staticmethod def parse(command: Command) -> None: @@ -262,7 +262,7 @@ def commands(self) -> list[Command]: :returns: The defined command """ - return [Command(id="os_release", command="cat /etc/os-release", parse=self.parse)] + return [Command(id_="os_release", command="cat /etc/os-release", parse=self.parse)] def parse(self, command) -> None: """Parse the output of the cat command. @@ -282,12 +282,12 @@ def commands(self) -> list[Command]: :returns: The defined command """ - pre = Command(id="pip_freeze", command="python3 -m pip freeze", parse=self.parse_freeze) + pre = Command(id_="pip_freeze", command="python3 -m pip freeze", parse=self.parse_freeze) run_command(pre) pre.parse(pre) pkgs = " ".join(pkg for pkg in pre.details[0]) return [ - Command(id="python_packages", command=f"python3 -m pip show {pkgs}", parse=self.parse), + Command(id_="python_packages", command=f"python3 -m pip show {pkgs}", parse=self.parse), ] def parse(self, command): @@ -323,7 +323,7 @@ def commands(self) -> list[Command]: :returns: The defined command """ - return [Command(id="redhat_release", command="cat /etc/redhat-release", parse=self.parse)] + return [Command(id_="redhat_release", command="cat /etc/redhat-release", parse=self.parse)] @staticmethod def parse(command): @@ -344,7 +344,7 @@ def commands(self) -> list[Command]: :returns: The defined command """ - return [Command(id="system_packages", command="rpm -qai", parse=self.parse)] + return [Command(id_="system_packages", command="rpm -qai", parse=self.parse)] def parse(self, command): """Parse the output of the rpm command. @@ -412,7 +412,7 @@ def main(): if key not in ["details", "errors"]: result_as_dict[f"__{key}"] = result_as_dict[key] result_as_dict.pop(key) - response[result_as_dict["__id"]] = result_as_dict + response[result_as_dict["__id_"]] = result_as_dict except Exception as exc: response["errors"].append(str(exc)) print(json.dumps(response)) diff --git a/src/ansible_navigator/image_manager/introspect.py b/src/ansible_navigator/image_manager/introspect.py index f100d60eb..97b71f5fa 100644 --- a/src/ansible_navigator/image_manager/introspect.py +++ b/src/ansible_navigator/image_manager/introspect.py @@ -22,7 +22,7 @@ class Command(SimpleNamespace): """Abstraction for a details about a shell command.""" - id: str + id_: str command: str parse: Callable stdout: str = "" diff --git a/src/ansible_navigator/ui_framework/form.py b/src/ansible_navigator/ui_framework/form.py index bb8e11d45..c6406f6e3 100644 --- a/src/ansible_navigator/ui_framework/form.py +++ b/src/ansible_navigator/ui_framework/form.py @@ -28,7 +28,7 @@ class Form: """Simple abstraction to hold the fields of the form and a convenience method to present it.""" - type: FormType + type_: FormType cancelled: bool = False fields: list = field(default_factory=list) submitted: bool = False @@ -44,7 +44,7 @@ def present(self, screen, ui_config): :param screen: A curses window :param ui_config: The current user interface configuration """ - if self.type is FormType.FORM: + if self.type_ is FormType.FORM: self.fields.append( FieldButton( name="submit", @@ -54,7 +54,7 @@ def present(self, screen, ui_config): ), ) self.fields.append(FieldButton(name="cancel", text="Cancel", color=9)) - elif self.type is FormType.NOTIFICATION: + elif self.type_ is FormType.NOTIFICATION: self.fields.append( FieldButton( name="submit", @@ -63,7 +63,7 @@ def present(self, screen, ui_config): color=10, ), ) - elif self.type is FormType.WORKING: + elif self.type_ is FormType.WORKING: pass FormPresenter(form=self, screen=screen, ui_config=ui_config).present() @@ -142,9 +142,9 @@ def _dimensions(self): widths.append(max(len(msg) for msg in form_field.messages)) widths.append(len(form_field.validator(hint=True)) + self._input_start) - if self._form.type is FormType.FORM: + if self._form.type_ is FormType.FORM: self._form_width = max(widths) + BUTTON_SPACE - elif self._form.type in (FormType.NOTIFICATION, FormType.WORKING): + elif self._form.type_ in (FormType.NOTIFICATION, FormType.WORKING): self._form_width = max(widths) height = 2 # title + horizontal line diff --git a/src/ansible_navigator/ui_framework/form_utils.py b/src/ansible_navigator/ui_framework/form_utils.py index 1f3c8fd86..df7a043fa 100644 --- a/src/ansible_navigator/ui_framework/form_utils.py +++ b/src/ansible_navigator/ui_framework/form_utils.py @@ -35,11 +35,11 @@ def dict_to_form(form_data: dict) -> Form: :returns: Object containing fields from form """ if form_data.get("type") == "notification": - form = Form(type=FormType.NOTIFICATION) + form = Form(type_=FormType.NOTIFICATION) elif form_data.get("type") == "working": - form = Form(type=FormType.WORKING) + form = Form(type_=FormType.WORKING) else: - form = Form(type=FormType.FORM) + form = Form(type_=FormType.FORM) form._dict = form_data # pylint: disable=protected-access form.title = form_data["title"] diff --git a/src/ansible_navigator/utils/key_value_store.py b/src/ansible_navigator/utils/key_value_store.py index 40c2578b7..8395d71ed 100644 --- a/src/ansible_navigator/utils/key_value_store.py +++ b/src/ansible_navigator/utils/key_value_store.py @@ -49,7 +49,7 @@ def close(self) -> None: self.conn.commit() self.conn.close() - def open(self) -> sqlite3.Connection: + def open_(self) -> sqlite3.Connection: """Establish the connection to the database. :returns: A connection to the database diff --git a/tests/integration/_interactions.py b/tests/integration/_interactions.py index 71290e3fe..c8ff4722c 100644 --- a/tests/integration/_interactions.py +++ b/tests/integration/_interactions.py @@ -21,7 +21,7 @@ class Command(NamedTuple): execution_environment: bool cmdline: str | None = None command: str = "ansible-navigator" - format: str | None = None + format_: str | None = None log_level: str = "debug" mode: str = "interactive" pass_environment_variables: list = [] @@ -44,8 +44,8 @@ def join(self) -> str: args.extend(["--ee", str(self.execution_environment)]) args.extend(["--ll", self.log_level]) args.extend(["--mode", self.mode]) - if self.format: - args.extend(["--format", self.format]) + if self.format_: + args.extend(["--format", self.format_]) if self.pass_environment_variables: for env_var in self.pass_environment_variables: args.extend(["--penv", env_var]) diff --git a/tests/integration/actions/images/test_stdout_tmux.py b/tests/integration/actions/images/test_stdout_tmux.py index 1f6df52c1..d58f0c84c 100644 --- a/tests/integration/actions/images/test_stdout_tmux.py +++ b/tests/integration/actions/images/test_stdout_tmux.py @@ -92,7 +92,7 @@ class ShellCommand(UiTestStep): user_input=StdoutCommand( cmdline="", mode="stdout", - format="json", + format_="json", execution_environment=True, raw_append=" | grep creator", ).join(), diff --git a/tests/unit/utils/test_functions.py b/tests/unit/utils/test_functions.py index c1ef9520f..ab0709975 100644 --- a/tests/unit/utils/test_functions.py +++ b/tests/unit/utils/test_functions.py @@ -128,24 +128,24 @@ def test_flatten_list(value: list, anticipated_result: list) -> None: class HumanTimeTestData(NamedTuple): """Data for human time test.""" - id: str + id_: str value: int | float expected: str human_time_test_data = [ - HumanTimeTestData(id="s", value=1, expected="1s"), - HumanTimeTestData(id="m-s", value=60 + 1, expected="1m1s"), - HumanTimeTestData(id="h-m-s", value=3600 + 60 + 1, expected="1h1m1s"), + HumanTimeTestData(id_="s", value=1, expected="1s"), + HumanTimeTestData(id_="m-s", value=60 + 1, expected="1m1s"), + HumanTimeTestData(id_="h-m-s", value=3600 + 60 + 1, expected="1h1m1s"), HumanTimeTestData( - id="d-h-m-s", + id_="d-h-m-s", value=86400 + 3600 + 60 + 1, expected="1d1h1m1s", ), ] -@pytest.mark.parametrize("data", human_time_test_data, ids=lambda data: data.id) +@pytest.mark.parametrize("data", human_time_test_data, ids=lambda data: data.id_) def test_human_time_integer(data: HumanTimeTestData) -> None: """Test for the functions.human_time function (integer passed). @@ -169,7 +169,7 @@ def test_human_time_negative_integer(data: HumanTimeTestData) -> None: assert result == f"-{data.expected}" -@pytest.mark.parametrize("data", human_time_test_data, ids=lambda data: data.id) +@pytest.mark.parametrize("data", human_time_test_data, ids=lambda data: data.id_) def test_human_time_float(data: HumanTimeTestData) -> None: """Test for the functions.human_time function (float passed). @@ -181,7 +181,7 @@ def test_human_time_float(data: HumanTimeTestData) -> None: assert result == data.expected -@pytest.mark.parametrize("data", human_time_test_data, ids=lambda data: data.id) +@pytest.mark.parametrize("data", human_time_test_data, ids=lambda data: data.id_) def test_human_time_negative_float(data: HumanTimeTestData) -> None: """Test for the functions.human_time function (negative float passed). @@ -196,24 +196,24 @@ def test_human_time_negative_float(data: HumanTimeTestData) -> None: class RoundHalfUpTestData(NamedTuple): """Data for round half up tests.""" - id: str + id_: str value: int | float expected: int round_half_up_test_data = [ - RoundHalfUpTestData(id="integer", value=1, expected=1), - RoundHalfUpTestData(id="negative-integer", value=-1, expected=-1), - RoundHalfUpTestData(id="down-float", value=1.49999999, expected=1), - RoundHalfUpTestData(id="up-float", value=1.50000001, expected=2), - RoundHalfUpTestData(id="negative-down-float", value=-1.49999999, expected=-1), - RoundHalfUpTestData(id="negative-up-float", value=-1.50000001, expected=-2), - RoundHalfUpTestData(id="half_even", value=2.5, expected=3), - RoundHalfUpTestData(id="half_even", value=3.5, expected=4), + RoundHalfUpTestData(id_="integer", value=1, expected=1), + RoundHalfUpTestData(id_="negative-integer", value=-1, expected=-1), + RoundHalfUpTestData(id_="down-float", value=1.49999999, expected=1), + RoundHalfUpTestData(id_="up-float", value=1.50000001, expected=2), + RoundHalfUpTestData(id_="negative-down-float", value=-1.49999999, expected=-1), + RoundHalfUpTestData(id_="negative-up-float", value=-1.50000001, expected=-2), + RoundHalfUpTestData(id_="half_even", value=2.5, expected=3), + RoundHalfUpTestData(id_="half_even", value=3.5, expected=4), ] -@pytest.mark.parametrize("data", round_half_up_test_data, ids=lambda data: data.id) +@pytest.mark.parametrize("data", round_half_up_test_data, ids=lambda data: data.id_) def test_round_half_up(data: RoundHalfUpTestData) -> None: """Test for the functions.round_half_up function.