From d73fe28ec4b3e4bd1f9de2b9761de36a85a490c0 Mon Sep 17 00:00:00 2001 From: "Dr.-Ing. Amilcar do Carmo Lucas" Date: Tue, 19 Nov 2024 10:21:41 +0100 Subject: [PATCH] FIX: all current linter issues --- .github/workflows/mypy.yml | 2 +- .github/workflows/pylint.yml | 2 +- MethodicConfigurator/annotate_params.py | 4 ++-- MethodicConfigurator/backend_filesystem.py | 2 +- .../backend_filesystem_configuration_steps.py | 4 ++-- .../backend_filesystem_program_settings.py | 7 ++++--- MethodicConfigurator/backend_mavftp.py | 6 +++--- MethodicConfigurator/frontend_tkinter_base.py | 6 +++--- MethodicConfigurator/frontend_tkinter_component_editor.py | 2 +- .../frontend_tkinter_connection_selection.py | 2 +- .../frontend_tkinter_directory_selection.py | 4 ++-- MethodicConfigurator/frontend_tkinter_entry_dynamic.py | 2 +- .../frontend_tkinter_parameter_editor_table.py | 2 +- MethodicConfigurator/mavftp_example.py | 2 +- MethodicConfigurator/tempcal_imu.py | 8 ++++---- 15 files changed, 28 insertions(+), 27 deletions(-) diff --git a/.github/workflows/mypy.yml b/.github/workflows/mypy.yml index 92621d7..a258ea0 100644 --- a/.github/workflows/mypy.yml +++ b/.github/workflows/mypy.yml @@ -21,7 +21,7 @@ jobs: - name: Install dependencies run: | - python -m pip install -U mypy + python -m pip install -U mypy types-requests - name: Lint the code with mypy uses: sasanquaneuf/mypy-github-action@releases/v1.3 diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml index 98116bd..beab4ad 100644 --- a/.github/workflows/pylint.yml +++ b/.github/workflows/pylint.yml @@ -29,7 +29,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install 'pylint<=3.2.7' + pip install 'pylint>=3.3.1' - name: Analysing the code with pylint run: | diff --git a/MethodicConfigurator/annotate_params.py b/MethodicConfigurator/annotate_params.py index a955b3d..f94e8c2 100755 --- a/MethodicConfigurator/annotate_params.py +++ b/MethodicConfigurator/annotate_params.py @@ -184,7 +184,7 @@ def load_param_file_into_dict(param_file: str) -> dict[str, "Par"]: return parameter_dict @staticmethod - def validate_parameter(param_file, parameter_dict, i, original_line, comment, parameter, value) -> None: # pylint: disable=too-many-arguments + def validate_parameter(param_file, parameter_dict, i, original_line, comment, parameter, value) -> None: # pylint: disable=too-many-arguments, too-many-positional-arguments if len(parameter) > PARAM_NAME_MAX_LEN: raise SystemExit(f"Too long parameter name: {parameter} in {param_file} line {i}") if not re.match(PARAM_NAME_REGEX, parameter): @@ -639,7 +639,7 @@ def update_parameter_documentation( ) -def update_parameter_documentation_file( # pylint: disable=too-many-locals, too-many-arguments +def update_parameter_documentation_file( # pylint: disable=too-many-locals, too-many-arguments, too-many-positional-arguments doc, sort_type, param_default_dict, diff --git a/MethodicConfigurator/backend_filesystem.py b/MethodicConfigurator/backend_filesystem.py index ae98d9b..104bd45 100644 --- a/MethodicConfigurator/backend_filesystem.py +++ b/MethodicConfigurator/backend_filesystem.py @@ -25,7 +25,7 @@ from typing import Any, Optional from zipfile import ZipFile -from requests import get as requests_get # type: ignore[import-untyped] +from requests import get as requests_get from MethodicConfigurator import _ from MethodicConfigurator.annotate_params import ( diff --git a/MethodicConfigurator/backend_filesystem_configuration_steps.py b/MethodicConfigurator/backend_filesystem_configuration_steps.py index 65df133..eef6c08 100644 --- a/MethodicConfigurator/backend_filesystem_configuration_steps.py +++ b/MethodicConfigurator/backend_filesystem_configuration_steps.py @@ -112,7 +112,7 @@ def __validate_parameters_in_configuration_steps(self, filename: str, file_info: parameter, ) - def compute_parameters(self, filename: str, file_info: dict, parameter_type: str, variables: dict) -> str: + def compute_parameters(self, filename: str, file_info: dict, parameter_type: str, variables: dict) -> str: # pylint: disable=too-many-branches """ Computes the forced or derived parameters for a given configuration file. @@ -122,7 +122,7 @@ def compute_parameters(self, filename: str, file_info: dict, parameter_type: str if parameter_type + "_parameters" not in file_info or not variables: return "" destination = self.forced_parameters if parameter_type == "forced" else self.derived_parameters - for parameter, parameter_info in file_info[parameter_type + "_parameters"].items(): + for parameter, parameter_info in file_info[parameter_type + "_parameters"].items(): # pylint: disable=too-many-nested-blocks try: if ("fc_parameters" in str(parameter_info["New Value"])) and ( "fc_parameters" not in variables or variables["fc_parameters"] == {} diff --git a/MethodicConfigurator/backend_filesystem_program_settings.py b/MethodicConfigurator/backend_filesystem_program_settings.py index 159cd3a..dd802a0 100644 --- a/MethodicConfigurator/backend_filesystem_program_settings.py +++ b/MethodicConfigurator/backend_filesystem_program_settings.py @@ -100,7 +100,7 @@ def __user_config_dir() -> str: error_msg = _("The path '{user_config_directory}' is not a directory.") raise NotADirectoryError(error_msg.format(**locals())) - return user_config_directory + return user_config_directory # type: ignore[no-any-return] # workaround a mypy bug @staticmethod def __site_config_dir() -> str: @@ -115,7 +115,7 @@ def __site_config_dir() -> str: error_msg = _("The path '{site_config_directory}' is not a directory.") raise NotADirectoryError(error_msg.format(**locals())) - return site_config_directory + return site_config_directory # type: ignore[no-any-return] # workaround a mypy bug @staticmethod def __get_settings_as_dict() -> dict[str, Any]: @@ -250,7 +250,8 @@ def set_display_usage_popup(ptype: str, value: bool) -> None: @staticmethod def get_setting(setting: str) -> Union[int, bool]: if setting in SETTINGS_DEFAULTS: - return ProgramSettings.__get_settings_as_dict().get(setting, SETTINGS_DEFAULTS[setting]) # type: ignore[no-any-return] + setting_default = SETTINGS_DEFAULTS[setting] + return ProgramSettings.__get_settings_as_dict().get(setting, setting_default) # type: ignore[no-any-return] return False @staticmethod diff --git a/MethodicConfigurator/backend_mavftp.py b/MethodicConfigurator/backend_mavftp.py index 9217675..7fe6c8d 100644 --- a/MethodicConfigurator/backend_mavftp.py +++ b/MethodicConfigurator/backend_mavftp.py @@ -86,7 +86,7 @@ class FTP_OP: # pylint: disable=invalid-name, too-many-instance-attributes including the necessary parameters and payload for the operation. """ - def __init__( # pylint: disable=too-many-arguments + def __init__( # pylint: disable=too-many-arguments, too-many-positional-arguments self, seq, session, @@ -216,7 +216,7 @@ def __setattr__(self, name, value) -> None: class MAVFTPReturn: """The result of a MAVFTP operation.""" - def __init__( # pylint: disable=too-many-arguments + def __init__( # pylint: disable=too-many-arguments, too-many-positional-arguments self, operation_name: str, error_code: int, @@ -1348,7 +1348,7 @@ def save_params( f.write("\n") logging.info("Outputted %u parameters to %s", len(pdict), filename) - def cmd_getparams( # pylint: disable=too-many-arguments + def cmd_getparams( # pylint: disable=too-many-arguments, too-many-positional-arguments self, args, progress_callback=None, diff --git a/MethodicConfigurator/frontend_tkinter_base.py b/MethodicConfigurator/frontend_tkinter_base.py index 4bc6edb..a476ca3 100644 --- a/MethodicConfigurator/frontend_tkinter_base.py +++ b/MethodicConfigurator/frontend_tkinter_base.py @@ -217,7 +217,7 @@ class ProgressWindow: a task. It includes a progress bar and a label to display the progress message. """ - def __init__(self, parent, title: str, message: str = "", width: int = 300, height: int = 80) -> None: # pylint: disable=too-many-arguments + def __init__(self, parent, title: str, message: str = "", width: int = 300, height: int = 80) -> None: # pylint: disable=too-many-arguments, too-many-positional-arguments self.parent = parent self.message = message self.progress_window = tk.Toplevel(self.parent) @@ -384,7 +384,7 @@ def put_image_in_label(parent: ttk.Frame, filepath: str, image_height: int = 40) photo = ImageTk.PhotoImage(resized_image) # Create a label with the resized image - image_label = ttk.Label(parent, image=photo) # type: ignore[arg-type] + image_label = ttk.Label(parent, image=photo) # Keep a reference to the image to prevent it from being garbage collected image_label.image = photo # type: ignore return image_label @@ -406,7 +406,7 @@ def should_display(ptype: str) -> bool: return ProgramSettings.display_usage_popup(ptype) @staticmethod - def display( # pylint: disable=too-many-arguments + def display( # pylint: disable=too-many-arguments, too-many-positional-arguments parent: tk.Toplevel, usage_popup_window: BaseWindow, title: str, diff --git a/MethodicConfigurator/frontend_tkinter_component_editor.py b/MethodicConfigurator/frontend_tkinter_component_editor.py index 2cb305d..b5c7843 100644 --- a/MethodicConfigurator/frontend_tkinter_component_editor.py +++ b/MethodicConfigurator/frontend_tkinter_component_editor.py @@ -617,7 +617,7 @@ def validate_combobox(self, event: tk.Event, path: tuple[str, ...]) -> bool: combobox.configure(style="comb_input_valid.TCombobox") return True - def validate_entry_limits(self, event, entry, data_type, limits, _name, path) -> bool: # pylint: disable=too-many-arguments + def validate_entry_limits(self, event, entry, data_type, limits, _name, path) -> bool: # pylint: disable=too-many-arguments, too-many-positional-arguments is_focusout_event = event and event.type == "10" try: value = entry.get() # make sure value is defined to prevent exception in the except block diff --git a/MethodicConfigurator/frontend_tkinter_connection_selection.py b/MethodicConfigurator/frontend_tkinter_connection_selection.py index 3b6c414..b56c3ed 100644 --- a/MethodicConfigurator/frontend_tkinter_connection_selection.py +++ b/MethodicConfigurator/frontend_tkinter_connection_selection.py @@ -32,7 +32,7 @@ class ConnectionSelectionWidgets: # pylint: disable=too-many-instance-attribute allowing the user to select a connection, and handling the connection process. """ - def __init__( # pylint: disable=too-many-arguments + def __init__( # pylint: disable=too-many-arguments, too-many-positional-arguments self, parent, parent_frame, diff --git a/MethodicConfigurator/frontend_tkinter_directory_selection.py b/MethodicConfigurator/frontend_tkinter_directory_selection.py index 7bd0178..873ae24 100644 --- a/MethodicConfigurator/frontend_tkinter_directory_selection.py +++ b/MethodicConfigurator/frontend_tkinter_directory_selection.py @@ -36,7 +36,7 @@ class DirectorySelectionWidgets: directory selection dialog. """ - def __init__( # pylint: disable=too-many-arguments + def __init__( # pylint: disable=too-many-arguments, too-many-positional-arguments self, parent: BaseWindow, parent_frame: tk.Widget, @@ -145,7 +145,7 @@ class VehicleDirectorySelectionWidgets(DirectorySelectionWidgets): selected vehicle directory and re-initializing the filesystem with the new directory. """ - def __init__( # pylint: disable=too-many-arguments + def __init__( # pylint: disable=too-many-arguments, too-many-positional-arguments self, parent: BaseWindow, parent_frame: ttk.Widget, diff --git a/MethodicConfigurator/frontend_tkinter_entry_dynamic.py b/MethodicConfigurator/frontend_tkinter_entry_dynamic.py index 7fc9e66..0edc86a 100644 --- a/MethodicConfigurator/frontend_tkinter_entry_dynamic.py +++ b/MethodicConfigurator/frontend_tkinter_entry_dynamic.py @@ -33,7 +33,7 @@ class EntryWithDynamicalyFilteredListbox(Entry): # pylint: disable=too-many-anc Entry with dynamicaly filtered ListBox to emulate an inteligent combobox widget """ - def __init__( # pylint: disable=too-many-arguments + def __init__( # pylint: disable=too-many-arguments, too-many-positional-arguments self, master, list_of_items=None, diff --git a/MethodicConfigurator/frontend_tkinter_parameter_editor_table.py b/MethodicConfigurator/frontend_tkinter_parameter_editor_table.py index 0fd7eb4..13a9e59 100644 --- a/MethodicConfigurator/frontend_tkinter_parameter_editor_table.py +++ b/MethodicConfigurator/frontend_tkinter_parameter_editor_table.py @@ -295,7 +295,7 @@ def __update_new_value_entry_text(new_value_entry: ttk.Entry, value: float, para else: new_value_entry.configure(style="TEntry") - def __create_new_value_entry( # pylint: disable=too-many-arguments + def __create_new_value_entry( # pylint: disable=too-many-arguments, too-many-positional-arguments self, param_name, param, diff --git a/MethodicConfigurator/mavftp_example.py b/MethodicConfigurator/mavftp_example.py index 5b32c49..8ccc253 100755 --- a/MethodicConfigurator/mavftp_example.py +++ b/MethodicConfigurator/mavftp_example.py @@ -21,7 +21,7 @@ import backend_mavftp as mavftp # import time -import requests # type: ignore[import-untyped] +import requests from pymavlink import mavutil old_mavftp_member_variable_values: dict[str, Any] = {} diff --git a/MethodicConfigurator/tempcal_imu.py b/MethodicConfigurator/tempcal_imu.py index 70d5b34..73d6066 100644 --- a/MethodicConfigurator/tempcal_imu.py +++ b/MethodicConfigurator/tempcal_imu.py @@ -104,7 +104,7 @@ def set_accel_tcal(self, imu, value) -> None: def set_enable(self, imu, value) -> None: self.enable[imu] = value - def correction(self, coeff, imu, temperature, axis, cal_temp) -> float: # pylint: disable=too-many-arguments + def correction(self, coeff, imu, temperature, axis, cal_temp) -> float: # pylint: disable=too-many-arguments, too-many-positional-arguments """calculate correction from temperature calibration from log data using parameters""" if self.enable[imu] != 1.0: return 0.0 @@ -286,7 +286,7 @@ def constrain(value, minv, maxv) -> Union[float, int]: return value # type: ignore -def IMUfit( # noqa: PLR0915 pylint: disable=too-many-locals, too-many-branches, too-many-statements, too-many-arguments +def IMUfit( # noqa: PLR0915 pylint: disable=too-many-locals, too-many-branches, too-many-statements, too-many-arguments, too-many-positional-arguments logfile, outfile, no_graph, @@ -539,7 +539,7 @@ def generate_calibration_file(outfile, online, progress_callback, data, c) -> tu return c, clog -def generate_tempcal_gyro_figures(log_parm, figpath, data, c, clog, num_imus) -> None: # pylint: disable=too-many-arguments +def generate_tempcal_gyro_figures(log_parm, figpath, data, c, clog, num_imus) -> None: # pylint: disable=too-many-arguments, too-many-positional-arguments _fig, axs = plt.subplots(len(data.IMUs()), 1, sharex=True) if num_imus == 1: axs = [axs] @@ -573,7 +573,7 @@ def generate_tempcal_gyro_figures(log_parm, figpath, data, c, clog, num_imus) -> _fig.savefig(os.path.join(figpath, "tempcal_gyro.png")) -def generate_tempcal_accel_figures(log_parm, figpath, data, c, clog, num_imus) -> None: # pylint: disable=too-many-arguments +def generate_tempcal_accel_figures(log_parm, figpath, data, c, clog, num_imus) -> None: # pylint: disable=too-many-arguments, too-many-positional-arguments _fig, axs = plt.subplots(num_imus, 1, sharex=True) if num_imus == 1: axs = [axs]