From 8de0a2f1d14eeb0bb2d7262c6cde61af2700e0d3 Mon Sep 17 00:00:00 2001 From: Brian Kroth Date: Mon, 25 Nov 2024 12:40:58 -0800 Subject: [PATCH] Pylint fixups (#886) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Pull Request ## Title Additional fixups for the most recent versions of python/pylint. --- ## Description - Converts some quote inconsistency ignores to `"""` strings - Ignores a `Generator` typehint issue that changed with 3.13 - Adjusts a comment in pyproject.toml to help us track what needs to change after dropping support for 3.8 - #749. --- ## Type of Change - 🔄 Refactor --- --- mlos_bench/mlos_bench/optimizers/base_optimizer.py | 2 +- mlos_bench/mlos_bench/optimizers/mlos_core_optimizer.py | 2 +- .../services/remote/azure/azure_network_services.py | 2 +- .../mlos_bench/services/remote/azure/azure_vm_services.py | 5 +++-- mlos_bench/mlos_bench/services/remote/ssh/ssh_service.py | 4 ++-- mlos_bench/mlos_bench/storage/util.py | 4 ++-- mlos_bench/mlos_bench/tests/dict_templater_test.py | 8 ++++---- pyproject.toml | 3 ++- 8 files changed, 16 insertions(+), 14 deletions(-) diff --git a/mlos_bench/mlos_bench/optimizers/base_optimizer.py b/mlos_bench/mlos_bench/optimizers/base_optimizer.py index 14eb3eba6ce..25824043daf 100644 --- a/mlos_bench/mlos_bench/optimizers/base_optimizer.py +++ b/mlos_bench/mlos_bench/optimizers/base_optimizer.py @@ -103,7 +103,7 @@ def _validate_json_config(self, config: dict) -> None: def __repr__(self) -> str: opt_targets = ",".join( - f"{opt_target}:{({1: 'min', -1: 'max'}[opt_dir])}" + f"""{opt_target}:{({1: "min", -1: "max"}[opt_dir])}""" for (opt_target, opt_dir) in self._opt_targets.items() ) return f"{self.name}({opt_targets},config={self._config})" diff --git a/mlos_bench/mlos_bench/optimizers/mlos_core_optimizer.py b/mlos_bench/mlos_bench/optimizers/mlos_core_optimizer.py index f9d5685ae8f..327c0e6aba7 100644 --- a/mlos_bench/mlos_bench/optimizers/mlos_core_optimizer.py +++ b/mlos_bench/mlos_bench/optimizers/mlos_core_optimizer.py @@ -65,7 +65,7 @@ def __init__( if "max_trials" not in self._config: self._config["max_trials"] = self._max_suggestions assert int(self._config["max_trials"]) >= self._max_suggestions, ( - f"max_trials {self._config.get('max_trials')} " + f"""max_trials {self._config.get("max_trials")} """ f"<= max_suggestions{self._max_suggestions}" ) diff --git a/mlos_bench/mlos_bench/services/remote/azure/azure_network_services.py b/mlos_bench/mlos_bench/services/remote/azure/azure_network_services.py index 4f11e89aa2f..de1a5a7118a 100644 --- a/mlos_bench/mlos_bench/services/remote/azure/azure_network_services.py +++ b/mlos_bench/mlos_bench/services/remote/azure/azure_network_services.py @@ -84,7 +84,7 @@ def _set_default_params(self, params: dict) -> dict: # pylint: disable=no-self- # since this is a common way to set the deploymentName and can same some # config work for the caller. if "vnetName" in params and "deploymentName" not in params: - params["deploymentName"] = f"{params['vnetName']}-deployment" + params["deploymentName"] = f"""{params["vnetName"]}-deployment""" _LOG.info( "deploymentName missing from params. Defaulting to '%s'.", params["deploymentName"], diff --git a/mlos_bench/mlos_bench/services/remote/azure/azure_vm_services.py b/mlos_bench/mlos_bench/services/remote/azure/azure_vm_services.py index 856f5e99126..ff24cbaa66f 100644 --- a/mlos_bench/mlos_bench/services/remote/azure/azure_vm_services.py +++ b/mlos_bench/mlos_bench/services/remote/azure/azure_vm_services.py @@ -190,7 +190,8 @@ def _set_default_params(self, params: dict) -> dict: # pylint: disable=no-self- # since this is a common way to set the deploymentName and can same some # config work for the caller. if "vmName" in params and "deploymentName" not in params: - params["deploymentName"] = f"{params['vmName']}-deployment" + params["deploymentName"] = f"""{params["vmName"]}-deployment""" + _LOG.info( "deploymentName missing from params. Defaulting to '%s'.", params["deploymentName"], @@ -239,7 +240,7 @@ def wait_host_operation(self, params: dict) -> Tuple[Status, dict]: """ _LOG.info("Wait for operation on VM %s", params["vmName"]) # Try and provide a semi sane default for the deploymentName - params.setdefault(f"{params['vmName']}-deployment") + params.setdefault(f"""{params["vmName"]}-deployment""") return self._wait_while(self._check_operation_status, Status.RUNNING, params) def wait_remote_exec_operation(self, params: dict) -> Tuple["Status", dict]: diff --git a/mlos_bench/mlos_bench/services/remote/ssh/ssh_service.py b/mlos_bench/mlos_bench/services/remote/ssh/ssh_service.py index 7e33d715ec3..c0590e55cfa 100644 --- a/mlos_bench/mlos_bench/services/remote/ssh/ssh_service.py +++ b/mlos_bench/mlos_bench/services/remote/ssh/ssh_service.py @@ -70,8 +70,8 @@ def id_from_connection(connection: SSHClientConnection) -> str: def id_from_params(connect_params: dict) -> str: """Gets a unique id repr for the connection.""" return ( - f"{connect_params.get('username')}@{connect_params['host']}" - f":{connect_params.get('port')}" + f"""{connect_params.get("username")}@{connect_params["host"]}""" + f""":{connect_params.get("port")}""" ) def connection_made(self, conn: SSHClientConnection) -> None: diff --git a/mlos_bench/mlos_bench/storage/util.py b/mlos_bench/mlos_bench/storage/util.py index 173f7d95d69..e1c6c1fa054 100644 --- a/mlos_bench/mlos_bench/storage/util.py +++ b/mlos_bench/mlos_bench/storage/util.py @@ -30,10 +30,10 @@ def kv_df_to_dict(dataframe: pandas.DataFrame) -> Dict[str, Optional[TunableValu data = {} for _, row in dataframe.astype("O").iterrows(): if not isinstance(row["value"], TunableValueTypeTuple): - raise TypeError(f"Invalid column type: {type(row['value'])} value: {row['value']}") + raise TypeError(f"""Invalid column type: {type(row["value"])} value: {row["value"]}""") assert isinstance(row["parameter"], str) if row["parameter"] in data: - raise ValueError(f"Duplicate parameter '{row['parameter']}' in dataframe") + raise ValueError(f"""Duplicate parameter '{row["parameter"]}' in dataframe""") data[row["parameter"]] = ( try_parse_val(row["value"]) if isinstance(row["value"], str) else row["value"] ) diff --git a/mlos_bench/mlos_bench/tests/dict_templater_test.py b/mlos_bench/mlos_bench/tests/dict_templater_test.py index 588d1f0ee40..52ec21bd5ae 100644 --- a/mlos_bench/mlos_bench/tests/dict_templater_test.py +++ b/mlos_bench/mlos_bench/tests/dict_templater_test.py @@ -85,7 +85,7 @@ def test_os_env_expansion(source_template_dict: Dict[str, Any]) -> None: results = DictTemplater(source_template_dict).expand_vars(use_os_env=True) assert results == { - "extra_str-ref": f"{environ['extra_str']}-ref", # pylint: disable=inconsistent-quotes + "extra_str-ref": f"""{environ["extra_str"]}-ref""", "str": "string", "str_ref": "string-ref", "secondary_expansion": "string-ref", @@ -103,7 +103,7 @@ def test_os_env_expansion(source_template_dict: Dict[str, Any]) -> None: ], "dict": { "nested-str-ref": "nested-string-ref", - "nested-extra-str-ref": f"nested-{environ['extra_str']}-ref", + "nested-extra-str-ref": f"""nested-{environ["extra_str"]}-ref""", }, } @@ -116,7 +116,7 @@ def test_from_extras_expansion(source_template_dict: Dict[str, Any]) -> None: } results = DictTemplater(source_template_dict).expand_vars(extra_source_dict=extra_source_dict) assert results == { - "extra_str-ref": f"{extra_source_dict['extra_str']}-ref", # pylint: disable=inconsistent-quotes # noqa: E501 + "extra_str-ref": f"""{extra_source_dict["extra_str"]}-ref""", "str": "string", "str_ref": "string-ref", "secondary_expansion": "string-ref", @@ -134,6 +134,6 @@ def test_from_extras_expansion(source_template_dict: Dict[str, Any]) -> None: ], "dict": { "nested-str-ref": "nested-string-ref", - "nested-extra-str-ref": f"nested-{extra_source_dict['extra_str']}-ref", # pylint: disable=inconsistent-quotes # noqa: E501 + "nested-extra-str-ref": f"""nested-{extra_source_dict["extra_str"]}-ref""", }, } diff --git a/pyproject.toml b/pyproject.toml index b5014df8a87..04595e1ed9b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -59,10 +59,11 @@ disable = [ "fixme", "no-else-return", "consider-using-assignment-expr", - "deprecated-typing-alias", # disable for now - only deprecated recently + "deprecated-typing-alias", # disable for now - still supporting python 3.8 "docstring-first-line-empty", "consider-alternative-union-syntax", # disable for now - still supporting python 3.8 "missing-raises-doc", + "unnecessary-default-type-args", # affects Generator type hints, but we still support python 3.8 ] [tool.pylint.string]