Skip to content

Commit e1fb6c8

Browse files
robertlong13peterbarker
authored andcommitted
Tools: fix type hints in param_check
We changed the default to None, but forgot to update the type hints. Also some drive-by whitespace cleanups.
1 parent 09119f9 commit e1fb6c8

File tree

3 files changed

+19
-16
lines changed

3 files changed

+19
-16
lines changed

Tools/scripts/param_check.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
3030
"""
3131

32+
from __future__ import annotations
3233
import os
3334
import json
3435
import re
@@ -80,7 +81,7 @@ def parse_arguments():
8081
return args
8182

8283

83-
def check_file(file, metadata, skip : SkippedChecks = None):
84+
def check_file(file, metadata, skip: SkippedChecks | None = None):
8485
"""Checks a single parameter file against the metadata.
8586
8687
Loads the parameters from the specified file and validates each parameter
@@ -129,7 +130,7 @@ def check_file(file, metadata, skip : SkippedChecks = None):
129130
return msgs
130131

131132

132-
def check_param(name, value, metadata, skip : SkippedChecks = None):
133+
def check_param(name, value, metadata, skip: SkippedChecks | None = None):
133134
"""Checks a single parameter against its metadata definition.
134135
135136
Validates the specified parameter. If the metadata contains multiple types
@@ -264,7 +265,7 @@ def check_values(name, value, metadata):
264265
return None
265266

266267

267-
def load_params(file, skip : SkippedChecks = None, depth=0):
268+
def load_params(file, skip: SkippedChecks | None = None, depth=0):
268269
"""Loads a parameter file and returns parameters and errors.
269270
270271
Reads the specified parameter file, stripping out comments. It checks the
@@ -484,7 +485,7 @@ def main():
484485
metadata = get_metadata(args.vehicle.split(','))
485486

486487
# Dictionary to store error messages for each file
487-
messages = {} # {filename: [error messages]}
488+
messages = {} # {filename: [error messages]}
488489

489490
# Check each file, and store any error messages
490491
for file in args.files:
@@ -507,4 +508,4 @@ def main():
507508

508509

509510
if __name__ == '__main__':
510-
main() # pragma: no cover
511+
main() # pragma: no cover

Tools/scripts/param_check_all.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,25 @@
66
AP_FLAKE8_CLEAN
77
'''
88

9+
from __future__ import annotations
910
import os
1011
import sys
1112
import glob
1213
from board_list import BoardList
1314
from param_check import get_metadata, check_file, SkippedChecks
1415

1516
sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../Tools', 'autotest'))
16-
from pysim.vehicleinfo import VehicleInfo # noqa: E402
17+
from pysim.vehicleinfo import VehicleInfo # noqa: E402
1718

1819

19-
periph_hwdefs_to_skip = set([ # Most of these fail due to NET_ params
20+
periph_hwdefs_to_skip = set([ # Most of these fail due to NET_ params
2021
'BotBloxDroneNet',
2122
'CubeNode-ETH',
2223
'CubeRedPrimary-PPPGW',
23-
'MatekG474-Periph', # Fails for RC_PORT
24+
'MatekG474-Periph', # Fails for RC_PORT
2425
'Pixhawk6X-PPPGW',
2526
'kha_eth',
26-
'sw-boom-f407', # Fails for ESC_NUM_POLES*
27+
'sw-boom-f407', # Fails for ESC_NUM_POLES*
2728
])
2829

2930
sitl_params_to_skip = set([
@@ -75,7 +76,7 @@
7576
ALL_VEHICLE_FIRMWARES = ['Sub', 'Plane', 'Blimp', 'Copter', 'Tracker', 'Rover']
7677

7778

78-
def check_boards(boards, firmwares, skip : SkippedChecks = None):
79+
def check_boards(boards, firmwares, skip: SkippedChecks | None = None):
7980
'''Check parameter files for ChibiOS hwdef boards.'''
8081
if skip is None:
8182
skip = SkippedChecks()
@@ -97,7 +98,7 @@ def check_boards(boards, firmwares, skip : SkippedChecks = None):
9798
return check_files(param_files, firmwares, skip=skip)
9899

99100

100-
def check_sitl(skip : SkippedChecks = None):
101+
def check_sitl(skip: SkippedChecks | None = None):
101102
'''Check every parameter file that shows up in vehicleinfo.py
102103
103104
Because this also provides us information about the intended firmware, we
@@ -150,7 +151,7 @@ def check_sitl(skip : SkippedChecks = None):
150151
return success
151152

152153

153-
def check_frame_params(skip : SkippedChecks = None):
154+
def check_frame_params(skip: SkippedChecks | None = None):
154155
'''Check all files within Tools/Frame_params
155156
156157
These don't contain any information about firmware (e.g. Copter, Plane,
@@ -177,7 +178,7 @@ def check_frame_params(skip : SkippedChecks = None):
177178
return check_files(param_files, ALL_VEHICLE_FIRMWARES, skip=skip)
178179

179180

180-
def check_files(files, firmwares, skip : SkippedChecks = None):
181+
def check_files(files, firmwares, skip: SkippedChecks | None = None):
181182
'''Check a list of parameter files against the metadata'''
182183
if skip is None:
183184
skip = SkippedChecks()

Tools/scripts/param_check_unittests.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
AP_FLAKE8_CLEAN
77
"""
88

9+
from __future__ import annotations
910
import os
1011
import time
1112
import unittest
@@ -236,7 +237,7 @@ def test_check_param(self):
236237

237238
# Test Bitmask
238239
del metadata['ReadOnly'] # Remove ReadOnly to test the next priority
239-
self.assertIsNone(check_param('PARAM', 256.0, metadata, skip)) # 256 would fail the other checks, but pass bitmask
240+
self.assertIsNone(check_param('PARAM', 256.0, metadata, skip)) # 256 would fail the other checks, but pass bitmask
240241
self.assertEqual(check_param('PARAM', 1.5, metadata, skip), 'PARAM: 1.5 is not an integer')
241242
self.assertEqual(check_param('PARAM', -1, metadata, skip), 'PARAM: -1 is negative')
242243
self.assertEqual(
@@ -249,7 +250,7 @@ def test_check_param(self):
249250

250251
# Test Range
251252
del metadata['Bitmask'] # Remove Bitmask to test the next priority
252-
self.assertIsNone(check_param('PARAM', 50, metadata, skip)) # 50 will fail the values check, but pass the range check
253+
self.assertIsNone(check_param('PARAM', 50, metadata, skip)) # 50 will fail the values check, but pass the range check
253254
self.assertEqual(check_param('PARAM', 101, metadata, skip), 'PARAM: 101 is above maximum value 100.0')
254255
self.assertEqual(check_param('PARAM', -1, metadata, skip), 'PARAM: -1 is below minimum value 0.0')
255256
skip.no_range = True
@@ -264,7 +265,7 @@ def test_check_param(self):
264265

265266
# Test parameter with no range, bitmask, or value restrictions
266267
del metadata['Values']
267-
self.assertIsNone(check_param('PARAM', 0, metadata, skip)) # Should pass no matter what
268+
self.assertIsNone(check_param('PARAM', 0, metadata, skip)) # Should pass no matter what
268269

269270
@patch('param_check.check_param')
270271
def test_check_file(self, mock_check_param):

0 commit comments

Comments
 (0)