Skip to content

Commit 30d576a

Browse files
committed
IMPROVEMENT: harmless mypy linting fixes
1 parent e78ee09 commit 30d576a

12 files changed

+47
-41
lines changed

MethodicConfigurator/backend_filesystem_program_settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ def set_display_usage_popup(ptype: str, value: bool) -> None:
250250
@staticmethod
251251
def get_setting(setting: str) -> Union[int, bool]:
252252
if setting in SETTINGS_DEFAULTS:
253-
return ProgramSettings.__get_settings_as_dict().get(setting, SETTINGS_DEFAULTS[setting])
253+
return ProgramSettings.__get_settings_as_dict().get(setting, SETTINGS_DEFAULTS[setting]) # type: ignore[no-any-return]
254254
return False
255255

256256
@staticmethod

MethodicConfigurator/backend_filesystem_vehicle_components.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from os import path as os_path
2222
from os import walk as os_walk
2323
from re import match as re_match
24+
from typing import Any, Union
2425

2526
from MethodicConfigurator import _
2627
from MethodicConfigurator.backend_filesystem_program_settings import ProgramSettings
@@ -35,7 +36,7 @@ class VehicleComponents:
3536

3637
def __init__(self) -> None:
3738
self.vehicle_components_json_filename = "vehicle_components.json"
38-
self.vehicle_components = None
39+
self.vehicle_components: Union[None, dict[Any, Any]] = None
3940

4041
def load_vehicle_components_json_data(self, vehicle_dir: str):
4142
data = {}

MethodicConfigurator/backend_flightcontroller.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ def __list_serial_ports() -> list[serial.tools.list_ports_common.ListPortInfo]:
477477
comports = serial.tools.list_ports.comports()
478478
# for port in comports:
479479
# logging_debug("ComPort - %s, Description: %s", port.device, port.description)
480-
return comports
480+
return comports # type: ignore[no-any-return]
481481

482482
@staticmethod
483483
def __list_network_ports() -> list[str]:

MethodicConfigurator/backend_flightcontroller_info.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,13 @@ def __decode_flight_capabilities(capabilities) -> dict[str, str]:
157157
# pymavlink.dialects.v20.ardupilotmega.enums["MAV_TYPE"]
158158
@staticmethod
159159
def __decode_mav_type(mav_type) -> str:
160-
return mavutil.mavlink.enums["MAV_TYPE"].get(mav_type, mavutil.mavlink.EnumEntry("None", "Unknown type")).description
160+
return str(
161+
mavutil.mavlink.enums["MAV_TYPE"].get(mav_type, mavutil.mavlink.EnumEntry("None", "Unknown type")).description
162+
)
161163

162164
@staticmethod
163165
def __decode_mav_autopilot(mav_autopilot) -> str:
164-
return (
166+
return str(
165167
mavutil.mavlink.enums["MAV_AUTOPILOT"]
166168
.get(mav_autopilot, mavutil.mavlink.EnumEntry("None", "Unknown type"))
167169
.description

MethodicConfigurator/backend_mavftp.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
import time
2020
from argparse import ArgumentParser
2121
from datetime import datetime
22+
from io import BufferedReader, BufferedWriter
2223
from io import BytesIO as SIO
24+
from typing import Union
2325

2426
from pymavlink import mavutil
2527

@@ -91,17 +93,17 @@ def __init__( # pylint: disable=too-many-arguments
9193
opcode,
9294
size,
9395
req_opcode,
94-
burst_complete,
95-
offset,
96+
burst_complete: bool,
97+
offset: int,
9698
payload,
9799
) -> None:
98100
self.seq = seq # Sequence number for the operation.
99101
self.session = session # Session identifier.
100102
self.opcode = opcode # Operation code indicating the type of FTP operation.
101103
self.size = size # Size of the operation.
102104
self.req_opcode = req_opcode # Request operation code.
103-
self.burst_complete = burst_complete # (bool) Flag indicating if the burst transfer is complete.
104-
self.offset = offset # Offset for read/write operations.
105+
self.burst_complete: bool = burst_complete # (bool) Flag indicating if the burst transfer is complete.
106+
self.offset: int = offset # Offset for read/write operations.
105107
self.payload = payload # (bytes) Payload for the operation.
106108

107109
def pack(self):
@@ -157,8 +159,8 @@ class ParamData:
157159
"""
158160

159161
def __init__(self) -> None:
160-
self.params = [] # params as (name, value, ptype)
161-
self.defaults = None # defaults as (name, value, ptype)
162+
self.params: list[tuple[str, float, type]] = [] # params as (name, value, ptype)
163+
self.defaults: Union[None, list[tuple[str, float, type]]] = None # defaults as (name, value, ptype)
162164

163165
def add_param(self, name, value, ptype) -> None:
164166
self.params.append((name, value, ptype))
@@ -183,7 +185,7 @@ class MAVFTPSettings:
183185
"""A collection of MAVFTP settings."""
184186

185187
def __init__(self, s_vars) -> None:
186-
self._vars = {}
188+
self._vars: dict[str, MAVFTPSetting] = {}
187189
for v in s_vars:
188190
self.append(v)
189191

@@ -315,40 +317,40 @@ def __init__(
315317
self.seq = 0
316318
self.session = 0
317319
self.network = 0
318-
self.last_op = None
319-
self.fh = None
320-
self.filename = None
320+
self.last_op: Union[None, FTP_OP] = None
321+
self.fh: Union[None, SIO, BufferedReader, BufferedWriter] = None
322+
self.filename: Union[None, str] = None
321323
self.callback = None
322324
self.callback_progress = None
323325
self.put_callback = None
324326
self.put_callback_progress = None
325327
self.total_size = 0
326-
self.read_gaps = []
327-
self.read_gap_times = {}
328+
self.read_gaps: list[tuple[int, int]] = []
329+
self.read_gap_times: dict[tuple[int, int], float] = {}
328330
self.last_gap_send = 0.0
329331
self.read_retries = 0
330332
self.read_total = 0
331333
self.remote_file_size = None
332334
self.duplicates = 0
333335
self.last_read = None
334-
self.last_burst_read = None
335-
self.op_start = None
336+
self.last_burst_read: Union[None, float] = None
337+
self.op_start: Union[None, float] = None
336338
self.dir_offset = 0
337339
self.last_op_time = time.time()
338340
self.last_send_time = time.time()
339341
self.rtt = 0.5
340342
self.reached_eof = False
341343
self.backlog = 0
342344
self.burst_size = self.ftp_settings.burst_read_size
343-
self.write_list = None
345+
self.write_list: Union[None, set[int]] = None
344346
self.write_block_size = 0
345347
self.write_acks = 0
346348
self.write_total = 0
347349
self.write_file_size = 0
348350
self.write_idx = 0
349351
self.write_recv_idx = -1
350352
self.write_pending = 0
351-
self.write_last_send = None
353+
self.write_last_send: Union[None, float] = None
352354
self.open_retries = 0
353355

354356
self.master = master
@@ -1217,7 +1219,7 @@ def __decode_ftp_ack_and_nack(self, op: FTP_OP, operation_name: str = "") -> MAV
12171219
)
12181220

12191221
@staticmethod
1220-
def ftp_param_decode(data) -> ParamData: # pylint: disable=too-many-locals
1222+
def ftp_param_decode(data) -> Union[None, ParamData]: # pylint: disable=too-many-locals
12211223
"""decode parameter data, returning ParamData"""
12221224
pdata = ParamData()
12231225

MethodicConfigurator/frontend_tkinter_component_editor_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def __init__(self, version, local_filesystem: LocalFilesystem) -> None:
114114
show_tooltip(self.save_button, _("Save component data and start parameter value configuration and tuning."))
115115
self.save_button.pack(pady=7)
116116
if UsagePopupWindow.should_display("component_editor"):
117-
self.root.after(10, self.__display_component_editor_usage_instructions(self.root))
117+
self.root.after(10, self.__display_component_editor_usage_instructions(self.root)) # type: ignore[arg-type]
118118

119119
@staticmethod
120120
def __display_component_editor_usage_instructions(parent: tk.Toplevel) -> None:

MethodicConfigurator/frontend_tkinter_directory_selection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class DirectorySelectionWidgets:
3838

3939
def __init__( # pylint: disable=too-many-arguments
4040
self,
41-
parent: tk.Toplevel,
41+
parent: BaseWindow,
4242
parent_frame: tk.Widget,
4343
initialdir: str,
4444
label_text: str,
@@ -147,7 +147,7 @@ class VehicleDirectorySelectionWidgets(DirectorySelectionWidgets):
147147

148148
def __init__( # pylint: disable=too-many-arguments
149149
self,
150-
parent: tk.Toplevel,
150+
parent: BaseWindow,
151151
parent_frame: ttk.Widget,
152152
local_filesystem: LocalFilesystem,
153153
initial_dir: str,

MethodicConfigurator/frontend_tkinter_flightcontroller_info.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def __init__(self, flight_controller: FlightController) -> None:
6868
logging_info(_("Flight Controller USB vendor ID: %s"), flight_controller.info.vendor)
6969
logging_info(_("Flight Controller USB product ID: %s"), flight_controller.info.product)
7070

71-
self.root.after(50, self.download_flight_controller_parameters()) # 50 milliseconds
71+
self.root.after(50, self.download_flight_controller_parameters()) # type: ignore[func-returns-value]
7272
self.root.mainloop()
7373

7474
def download_flight_controller_parameters(self) -> None:

MethodicConfigurator/frontend_tkinter_pair_tuple_combobox.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from platform import system as platform_system
2121
from sys import exit as sys_exit
2222
from tkinter import Label, Toplevel, ttk
23+
from typing import Union
2324

2425
from MethodicConfigurator import _
2526
from MethodicConfigurator.common_arguments import add_common_arguments_and_parse
@@ -37,8 +38,8 @@ class PairTupleCombobox(ttk.Combobox): # pylint: disable=too-many-ancestors
3738
def __init__(self, container, list_pair_tuple, selected_element, cb_name, *args, **kwargs) -> None:
3839
super().__init__(container, *args, **kwargs)
3940
self.cb_name = cb_name
40-
self.list_keys = []
41-
self.list_shows = []
41+
self.list_keys: list[str] = []
42+
self.list_shows: list[str] = []
4243
self.set_entries_tupple(list_pair_tuple, selected_element)
4344
self.bind("<Configure>", self.on_combo_configure, add="+")
4445

@@ -133,7 +134,7 @@ class PairTupleComboboxTooltip(PairTupleCombobox): # pylint: disable=too-many-a
133134

134135
def __init__(self, container, list_pair_tuple, selected_element, cb_name, *args, **kwargs) -> None:
135136
super().__init__(container, list_pair_tuple, selected_element, cb_name, *args, **kwargs)
136-
self.tooltip = None
137+
self.tooltip: Union[None, Toplevel] = None
137138

138139
# Bind events related to the dropdown
139140
pd = self.tk.call("ttk::combobox::PopdownWindow", self)

MethodicConfigurator/frontend_tkinter_parameter_editor.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,11 +284,11 @@ def __init__(self, current_file: str, flight_controller: FlightController, local
284284
self.__create_parameter_area_widgets()
285285

286286
# trigger a table update to ask the user what to do in the case this file needs special actions
287-
self.root.after(10, self.on_param_file_combobox_change(None, True))
287+
self.root.after(10, self.on_param_file_combobox_change(None, True)) # type: ignore[func-returns-value]
288288

289289
# this one should be on top of the previous one hence the longer time
290290
if UsagePopupWindow.should_display("parameter_editor"):
291-
self.root.after(100, self.__display_usage_popup_window(self.root))
291+
self.root.after(100, self.__display_usage_popup_window(self.root)) # type: ignore[arg-type]
292292
self.root.mainloop()
293293

294294
def __create_conf_widgets(self, version: str) -> None:
@@ -301,7 +301,7 @@ def __create_conf_widgets(self, version: str) -> None:
301301
# Create a new frame inside the config_subframe for the intermediate parameter file directory selection labels
302302
# and directory selection button
303303
directory_selection_frame = VehicleDirectorySelectionWidgets(
304-
self.root, config_subframe, self.local_filesystem, self.local_filesystem.vehicle_dir, destroy_parent_on_open=False
304+
self, config_subframe, self.local_filesystem, self.local_filesystem.vehicle_dir, destroy_parent_on_open=False
305305
)
306306
directory_selection_frame.container_frame.pack(side=tk.LEFT, fill="x", expand=False, padx=(4, 6))
307307

0 commit comments

Comments
 (0)