Skip to content

Commit eecb837

Browse files
committed
FIX: inconsistent return types
1 parent 2b9768b commit eecb837

10 files changed

+31
-27
lines changed

MethodicConfigurator/annotate_params.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ def get_xml_data(base_url: str, directory: str, filename: str, vehicle_type: str
390390
raise SystemExit("permission denied to write online XML documentation to file") from e
391391

392392
# Parse the XML data
393-
return DET.fromstring(xml_data)
393+
return DET.fromstring(xml_data) # type: ignore[no-any-return]
394394

395395

396396
def load_default_param_file(directory: str) -> dict[str, "Par"]:

MethodicConfigurator/backend_filesystem_configuration_steps.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,9 @@ def auto_changed_by(self, selected_file: str):
169169
return self.configuration_steps[selected_file].get("auto_changed_by", "")
170170
return ""
171171

172-
def jump_possible(self, selected_file: str):
172+
def jump_possible(self, selected_file: str) -> dict[str, str]:
173173
if selected_file in self.configuration_steps:
174-
return self.configuration_steps[selected_file].get("jump_possible", {})
174+
return dict(self.configuration_steps[selected_file].get("jump_possible", {}))
175175
return {}
176176

177177
def get_documentation_text_and_url(self, selected_file: str, prefix_key: str) -> tuple[str, str]:

MethodicConfigurator/backend_filesystem_program_settings.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from re import escape as re_escape
2222
from re import match as re_match
2323
from re import sub as re_sub
24+
from typing import Any
2425

2526
from platformdirs import site_config_dir, user_config_dir
2627

@@ -111,7 +112,7 @@ def __site_config_dir():
111112
return site_config_directory
112113

113114
@staticmethod
114-
def __get_settings_as_dict():
115+
def __get_settings_as_dict() -> dict[str, Any]:
115116
settings_path = os_path.join(ProgramSettings.__user_config_dir(), "settings.json")
116117

117118
settings = {}
@@ -226,8 +227,9 @@ def get_recently_used_dirs():
226227
return template_dir, new_base_dir, vehicle_dir
227228

228229
@staticmethod
229-
def display_usage_popup(ptype: str):
230-
return ProgramSettings.__get_settings_as_dict()["display_usage_popup"].get(ptype, True)
230+
def display_usage_popup(ptype: str) -> bool:
231+
display_usage_popup_settings = ProgramSettings.__get_settings_as_dict().get("display_usage_popup", {})
232+
return bool(display_usage_popup_settings.get(ptype, True))
231233

232234
@staticmethod
233235
def set_display_usage_popup(ptype: str, value: bool):

MethodicConfigurator/backend_filesystem_vehicle_components.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def get_fc_fw_type_from_vehicle_components_json(self) -> str:
6767
else:
6868
components = None
6969
if components:
70-
fw_type = components.get("Flight Controller", {}).get("Firmware", {}).get("Type", "")
70+
fw_type: str = components.get("Flight Controller", {}).get("Firmware", {}).get("Type", "")
7171
if fw_type in self.supported_vehicles():
7272
return fw_type
7373
error_msg = _("Firmware type {fw_type} in {self.vehicle_components_json_filename} is not supported")
@@ -80,7 +80,7 @@ def get_fc_fw_version_from_vehicle_components_json(self) -> str:
8080
else:
8181
components = None
8282
if components:
83-
version_str = components.get("Flight Controller", {}).get("Firmware", {}).get("Version", "")
83+
version_str: str = components.get("Flight Controller", {}).get("Firmware", {}).get("Version", "")
8484
version_str = version_str.lstrip().split(" ")[0] if version_str else ""
8585
if re_match(r"^\d+\.\d+\.\d+$", version_str):
8686
return version_str

MethodicConfigurator/backend_flightcontroller.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def discover_connections(self):
9595
for port in self.__connection_tuples:
9696
logging_info("%s - %s", port[0], port[1])
9797
# now that it is logged, add the 'Add another' tuple
98-
self.__connection_tuples += [tuple([_("Add another"), _("Add another")])]
98+
self.__connection_tuples += [(_("Add another"), _("Add another"))]
9999

100100
def disconnect(self):
101101
"""
@@ -222,7 +222,7 @@ def __request_message(self, message_id: int):
222222

223223
def __create_connection_with_retry(
224224
self, progress_callback, retries: int = 3, timeout: int = 5, log_errors: bool = True
225-
) -> mavutil.mavlink_connection:
225+
) -> str:
226226
"""
227227
Attempts to create a connection to the flight controller with retries.
228228

MethodicConfigurator/backend_mavftp.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,8 @@ def cmd_ftp(self, args) -> MAVFTPReturn: # noqa PRL0911 pylint: disable=too-man
368368
if args[0] == "list":
369369
return self.cmd_list(args[1:])
370370
if args[0] == "set":
371-
return self.ftp_settings.command(args[1:])
371+
self.ftp_settings.command(args[1:])
372+
return MAVFTPReturn("FTP command", ERR_None)
372373
if args[0] == "get":
373374
return self.cmd_get(args[1:])
374375
if args[0] == "getparams":
@@ -859,7 +860,7 @@ def cmd_rm(self, args) -> MAVFTPReturn:
859860
self.__send(op)
860861
return self.process_ftp_reply("RemoveFile")
861862

862-
def cmd_rmdir(self, args):
863+
def cmd_rmdir(self, args) -> MAVFTPReturn:
863864
"""remove directory"""
864865
if len(args) != 1:
865866
logging.error("Usage: rmdir [DIRECTORYNAME]")
@@ -871,7 +872,7 @@ def cmd_rmdir(self, args):
871872
self.__send(op)
872873
return self.process_ftp_reply("RemoveDirectory")
873874

874-
def __handle_remove_reply(self, op, _m):
875+
def __handle_remove_reply(self, op, _m) -> MAVFTPReturn:
875876
"""handle remove reply"""
876877
return self.__decode_ftp_ack_and_nack(op)
877878

@@ -890,7 +891,7 @@ def cmd_rename(self, args) -> MAVFTPReturn:
890891
self.__send(op)
891892
return self.process_ftp_reply("Rename")
892893

893-
def __handle_rename_reply(self, op, _m):
894+
def __handle_rename_reply(self, op, _m) -> MAVFTPReturn:
894895
"""handle rename reply"""
895896
return self.__decode_ftp_ack_and_nack(op)
896897

@@ -906,7 +907,7 @@ def cmd_mkdir(self, args) -> MAVFTPReturn:
906907
self.__send(op)
907908
return self.process_ftp_reply("CreateDirectory")
908909

909-
def __handle_mkdir_reply(self, op, _m):
910+
def __handle_mkdir_reply(self, op, _m) -> MAVFTPReturn:
910911
"""handle mkdir reply"""
911912
return self.__decode_ftp_ack_and_nack(op)
912913

@@ -924,7 +925,7 @@ def cmd_crc(self, args) -> MAVFTPReturn:
924925
self.__send(op)
925926
return self.process_ftp_reply("CalcFileCRC32")
926927

927-
def __handle_crc_reply(self, op, _m):
928+
def __handle_crc_reply(self, op, _m) -> MAVFTPReturn:
928929
"""handle crc reply"""
929930
if op.opcode == OP_Ack and op.size == 4:
930931
(crc,) = struct.unpack("<I", op.payload)
@@ -1119,9 +1120,9 @@ def __idle_task(self) -> bool:
11191120
return self.__last_send_time_was_more_than_idle_detection_time_ago(now)
11201121

11211122
def __last_send_time_was_more_than_idle_detection_time_ago(self, now: float) -> bool:
1122-
return self.last_send_time is not None and now - self.last_send_time > self.ftp_settings.idle_detection_time
1123+
return self.last_send_time is not None and now - self.last_send_time > float(self.ftp_settings.idle_detection_time)
11231124

1124-
def __handle_reset_sessions_reply(self, op, _m):
1125+
def __handle_reset_sessions_reply(self, op, _m) -> MAVFTPReturn:
11251126
"""handle reset sessions reply"""
11261127
return self.__decode_ftp_ack_and_nack(op)
11271128

@@ -1352,13 +1353,13 @@ def cmd_getparams( # pylint: disable=too-many-arguments
13521353
sort_type: str = "missionplanner",
13531354
add_datatype_comments: bool = False,
13541355
add_timestamp_comment: bool = False,
1355-
):
1356+
) -> MAVFTPReturn:
13561357
"""Decode the parameter file and save the values and defaults to disk"""
13571358

1358-
def decode_and_save_params(fh):
1359+
def decode_and_save_params(fh) -> MAVFTPReturn:
13591360
if fh is None:
13601361
logging.error("FTP: no parameter file handler")
1361-
return
1362+
return MAVFTPReturn("GetParams", ERR_Fail)
13621363
try:
13631364
data = fh.read()
13641365
except OSError as exp:
@@ -1383,8 +1384,9 @@ def decode_and_save_params(fh):
13831384
logging.info("%-16s %f (default %f)", name, value, param_defaults[name][0])
13841385
else:
13851386
logging.info("%-16s %f", name, value)
1387+
return MAVFTPReturn("GetParams", ERR_None)
13861388

1387-
self.cmd_get(
1389+
return self.cmd_get(
13881390
["@PARAM/param.pck?withdefaults=1" if len(args) > 1 else "@PARAM/param.pck"],
13891391
callback=decode_and_save_params,
13901392
progress_callback=progress_callback,

MethodicConfigurator/frontend_tkinter_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ def put_image_in_label(parent: ttk.Frame, filepath: str, image_height: int = 40)
384384
photo = ImageTk.PhotoImage(resized_image)
385385

386386
# Create a label with the resized image
387-
image_label = ttk.Label(parent, image=photo)
387+
image_label = ttk.Label(parent, image=photo) # type: ignore[arg-type]
388388
# Keep a reference to the image to prevent it from being garbage collected
389389
image_label.image = photo # type: ignore
390390
return image_label

MethodicConfigurator/frontend_tkinter_parameter_editor_table.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def __init__(self, root, local_filesystem, parameter_editor):
4848
self.root = root
4949
self.local_filesystem = local_filesystem
5050
self.parameter_editor = parameter_editor
51-
self.current_file = None
51+
self.current_file = ""
5252
self.upload_checkbutton_var = {}
5353
self.at_least_one_param_edited = False
5454

MethodicConfigurator/internationalization.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020
LANGUAGE_CHOICES = ["en", "zh_CN", "pt"]
2121

2222

23-
def identity_function(s):
23+
def identity_function(s: str) -> str:
2424
return s
2525

2626

27-
def load_translation() -> Callable:
27+
def load_translation() -> Callable[[str], str]:
2828
default_language = LANGUAGE_CHOICES[0]
2929

3030
# First, pre-parse to find the --language argument

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ no_implicit_optional = true
152152
# Configuring warnings
153153
warn_unused_ignores = true
154154
warn_no_return = false
155-
warn_return_any = false
155+
warn_return_any = true
156156
warn_redundant_casts = true
157157

158158
# Misc things

0 commit comments

Comments
 (0)