Skip to content

Commit 8af20af

Browse files
pylint: enforce indentation (W0311) (#24039)
* pylint: enforce indentation (W0311) * few more
1 parent 1df3c86 commit 8af20af

24 files changed

+194
-195
lines changed

.pylintrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ confidence=
5454
# --enable=similarities". If you want to run only the classes checker, but have
5555
# no Warning level messages displayed, use"--disable=all --enable=classes
5656
# --disable=W"
57-
disable=C,R,W0613,W0511,W0212,W0201,W0311,W0106,W0603,W0621,W0703,W1201,W1203,E1136,W1514
57+
disable=C,R,W0613,W0511,W0212,W0201,W0106,W0603,W0621,W0703,W1201,W1203,E1136,W1514
5858

5959

6060
# Enable the message, report, category or checker with the given id(s). You can

common/kalman/tests/test_simple_kalman.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ def test_getter_setter(self):
3636
self.assertEqual(self.kf.x, [[1.0], [1.0]])
3737

3838
def update_returns_state(self):
39-
x = self.kf.update(100)
40-
self.assertEqual(x, self.kf.x)
39+
x = self.kf.update(100)
40+
self.assertEqual(x, self.kf.x)
4141

4242
def test_old_equal_new(self):
4343
for _ in range(1000):

common/logging_extra.py

+22-22
Original file line numberDiff line numberDiff line change
@@ -172,33 +172,33 @@ def findCaller(self, stack_info=False, stacklevel=1):
172172
#On some versions of IronPython, currentframe() returns None if
173173
#IronPython isn't run with -X:Frames.
174174
if f is not None:
175-
f = f.f_back
175+
f = f.f_back
176176
orig_f = f
177177
while f and stacklevel > 1:
178-
f = f.f_back
179-
stacklevel -= 1
178+
f = f.f_back
179+
stacklevel -= 1
180180
if not f:
181-
f = orig_f
181+
f = orig_f
182182
rv = "(unknown file)", 0, "(unknown function)", None
183183
while hasattr(f, "f_code"):
184-
co = f.f_code
185-
filename = os.path.normcase(co.co_filename)
186-
187-
# TODO: is this pylint exception correct?
188-
if filename == _srcfile: # pylint: disable=comparison-with-callable
189-
f = f.f_back
190-
continue
191-
sinfo = None
192-
if stack_info:
193-
sio = io.StringIO()
194-
sio.write('Stack (most recent call last):\n')
195-
traceback.print_stack(f, file=sio)
196-
sinfo = sio.getvalue()
197-
if sinfo[-1] == '\n':
198-
sinfo = sinfo[:-1]
199-
sio.close()
200-
rv = (co.co_filename, f.f_lineno, co.co_name, sinfo)
201-
break
184+
co = f.f_code
185+
filename = os.path.normcase(co.co_filename)
186+
187+
# TODO: is this pylint exception correct?
188+
if filename == _srcfile: # pylint: disable=comparison-with-callable
189+
f = f.f_back
190+
continue
191+
sinfo = None
192+
if stack_info:
193+
sio = io.StringIO()
194+
sio.write('Stack (most recent call last):\n')
195+
traceback.print_stack(f, file=sio)
196+
sinfo = sio.getvalue()
197+
if sinfo[-1] == '\n':
198+
sinfo = sinfo[:-1]
199+
sio.close()
200+
rv = (co.co_filename, f.f_lineno, co.co_name, sinfo)
201+
break
202202
return rv
203203

204204
if __name__ == "__main__":

selfdrive/boardd/tests/test_boardd_api.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,4 @@ def test_performance(self):
7474

7575

7676
if __name__ == '__main__':
77-
unittest.main()
77+
unittest.main()

selfdrive/camerad/test/get_thumbnails_for_segment.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
lr = list(LogReader(path))
2525

2626
for msg in tqdm(lr):
27-
if msg.which() == 'thumbnail':
28-
with open(os.path.join(out_path, f"{msg.thumbnail.frameId}.jpg"), 'wb') as f:
29-
f.write(msg.thumbnail.thumbnail)
30-
elif msg.which() == 'navThumbnail':
31-
with open(os.path.join(out_path, f"nav_{msg.navThumbnail.frameId}.jpg"), 'wb') as f:
32-
f.write(msg.navThumbnail.thumbnail)
27+
if msg.which() == 'thumbnail':
28+
with open(os.path.join(out_path, f"{msg.thumbnail.frameId}.jpg"), 'wb') as f:
29+
f.write(msg.thumbnail.thumbnail)
30+
elif msg.which() == 'navThumbnail':
31+
with open(os.path.join(out_path, f"nav_{msg.navThumbnail.frameId}.jpg"), 'wb') as f:
32+
f.write(msg.navThumbnail.thumbnail)

selfdrive/car/honda/interface.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ def update(self, c, can_strings):
404404
# do enable on both accel and decel buttons
405405
if not self.CP.pcmCruise:
406406
if b.type in (ButtonType.accelCruise, ButtonType.decelCruise) and not b.pressed:
407-
events.add(EventName.buttonEnable)
407+
events.add(EventName.buttonEnable)
408408

409409
# do disable on button down
410410
if b.type == ButtonType.cancel and b.pressed:

selfdrive/car/nissan/carcontroller.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,14 @@ def update(self, c, CS, frame, actuators, cruise_cancel, hud_alert,
5858
self.last_angle = apply_angle
5959

6060
if self.CP.carFingerprint in (CAR.ROGUE, CAR.XTRAIL, CAR.ALTIMA) and cruise_cancel:
61-
can_sends.append(nissancan.create_acc_cancel_cmd(self.packer, self.car_fingerprint, CS.cruise_throttle_msg, frame))
61+
can_sends.append(nissancan.create_acc_cancel_cmd(self.packer, self.car_fingerprint, CS.cruise_throttle_msg, frame))
6262

6363
# TODO: Find better way to cancel!
6464
# For some reason spamming the cancel button is unreliable on the Leaf
6565
# We now cancel by making propilot think the seatbelt is unlatched,
6666
# this generates a beep and a warning message every time you disengage
6767
if self.CP.carFingerprint in (CAR.LEAF, CAR.LEAF_IC) and frame % 2 == 0:
68-
can_sends.append(nissancan.create_cancel_msg(self.packer, CS.cancel_msg, cruise_cancel))
68+
can_sends.append(nissancan.create_cancel_msg(self.packer, CS.cancel_msg, cruise_cancel))
6969

7070
can_sends.append(nissancan.create_steering_control(
7171
self.packer, apply_angle, frame, c.enabled, self.lkas_max_torque))

selfdrive/car/subaru/subarucan.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def create_es_lkas(packer, es_lkas_msg, enabled, visual_alert, left_line, right_
5454
values["LKAS_ACTIVE"] = 1 # Show LKAS lane lines
5555
values["LKAS_Dash_State"] = 2 # Green enabled indicator
5656
else:
57-
values["LKAS_Dash_State"] = 0 # LKAS Not enabled
57+
values["LKAS_Dash_State"] = 0 # LKAS Not enabled
5858

5959
values["LKAS_Left_Line_Visible"] = int(left_line)
6060
values["LKAS_Right_Line_Visible"] = int(right_line)

selfdrive/car/tests/test_fingerprints.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ def check_fingerprint_consistency(f1, f2):
3737
is_f1_in_f2 = True
3838
for k in f1:
3939
if (k not in f2 or f1[k] != f2[k]) and k < max_msg:
40-
is_f1_in_f2 = False
40+
is_f1_in_f2 = False
4141

4242
is_f2_in_f1 = True
4343
for k in f2:
4444
if (k not in f1 or f2[k] != f1[k]) and k < max_msg:
45-
is_f2_in_f1 = False
45+
is_f2_in_f1 = False
4646

4747
return not is_f1_in_f2 and not is_f2_in_f1
4848

selfdrive/debug/show_matching_cars.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010

1111

1212
for addr, l in fingerprint.items():
13-
dat = messaging.new_message('can', 1)
13+
dat = messaging.new_message('can', 1)
1414

15-
msg = dat.can[0]
16-
msg.address = addr
17-
msg.dat = " " * l
15+
msg = dat.can[0]
16+
msg.address = addr
17+
msg.dat = " " * l
1818

19-
candidate_cars = eliminate_incompatible_cars(msg, candidate_cars)
20-
print(candidate_cars)
19+
candidate_cars = eliminate_incompatible_cars(msg, candidate_cars)
20+
print(candidate_cars)

selfdrive/hardware/tici/hardware.py

+21-21
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,19 @@
2424
MM_SIM = MM + ".Sim"
2525

2626
class MM_MODEM_STATE(IntEnum):
27-
FAILED = -1
28-
UNKNOWN = 0
29-
INITIALIZING = 1
30-
LOCKED = 2
31-
DISABLED = 3
32-
DISABLING = 4
33-
ENABLING = 5
34-
ENABLED = 6
35-
SEARCHING = 7
36-
REGISTERED = 8
37-
DISCONNECTING = 9
38-
CONNECTING = 10
39-
CONNECTED = 11
27+
FAILED = -1
28+
UNKNOWN = 0
29+
INITIALIZING = 1
30+
LOCKED = 2
31+
DISABLED = 3
32+
DISABLING = 4
33+
ENABLING = 5
34+
ENABLED = 6
35+
SEARCHING = 7
36+
REGISTERED = 8
37+
DISCONNECTING = 9
38+
CONNECTING = 10
39+
CONNECTED = 11
4040

4141
class NMMetered(IntEnum):
4242
NM_METERED_UNKNOWN = 0
@@ -194,14 +194,14 @@ def get_network_info(self):
194194
return None
195195

196196
def parse_strength(self, percentage):
197-
if percentage < 25:
198-
return NetworkStrength.poor
199-
elif percentage < 50:
200-
return NetworkStrength.moderate
201-
elif percentage < 75:
202-
return NetworkStrength.good
203-
else:
204-
return NetworkStrength.great
197+
if percentage < 25:
198+
return NetworkStrength.poor
199+
elif percentage < 50:
200+
return NetworkStrength.moderate
201+
elif percentage < 75:
202+
return NetworkStrength.good
203+
else:
204+
return NetworkStrength.great
205205

206206
def get_network_strength(self, network_type):
207207
network_strength = NetworkStrength.unknown

selfdrive/locationd/models/loc_kf.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -474,14 +474,14 @@ def predict_and_update_odo_trans(self, trans, t, kind):
474474
z = trans[:, :3]
475475
R = np.zeros((len(trans), 3, 3))
476476
for i, _ in enumerate(z):
477-
R[i, :, :] = np.diag(trans[i, 3:]**2)
477+
R[i, :, :] = np.diag(trans[i, 3:]**2)
478478
return self.filter.predict_and_update_batch(t, kind, z, R)
479479

480480
def predict_and_update_odo_rot(self, rot, t, kind):
481481
z = rot[:, :3]
482482
R = np.zeros((len(rot), 3, 3))
483483
for i, _ in enumerate(z):
484-
R[i, :, :] = np.diag(rot[i, 3:]**2)
484+
R[i, :, :] = np.diag(rot[i, 3:]**2)
485485
return self.filter.predict_and_update_batch(t, kind, z, R)
486486

487487
def predict_and_update_orb_features(self, tracks, t, kind):
@@ -518,7 +518,7 @@ def predict_and_update_orb_features(self, tracks, t, kind):
518518

519519
y_full = np.zeros((z.shape[0], z.shape[1] - 3))
520520
if sum(good_idxs) > 0:
521-
y_full[good_idxs] = np.array(ret[6])
521+
y_full[good_idxs] = np.array(ret[6])
522522
ret = ret[:6] + (y_full, z, ecef_pos)
523523
return ret
524524

selfdrive/loggerd/tests/fill_eon.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@
2323
# Fill up to 99 percent
2424
available_percent = get_available_percent()
2525
if available_percent < 1.0:
26-
break
26+
break

selfdrive/loggerd/tests/loggerd_tests_common.py

+13-13
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,22 @@
88
import selfdrive.loggerd.uploader as uploader
99

1010
def create_random_file(file_path, size_mb, lock=False):
11-
try:
12-
os.mkdir(os.path.dirname(file_path))
13-
except OSError:
14-
pass
11+
try:
12+
os.mkdir(os.path.dirname(file_path))
13+
except OSError:
14+
pass
1515

16-
lock_path = file_path + ".lock"
17-
if lock:
18-
os.close(os.open(lock_path, os.O_CREAT | os.O_EXCL))
16+
lock_path = file_path + ".lock"
17+
if lock:
18+
os.close(os.open(lock_path, os.O_CREAT | os.O_EXCL))
1919

20-
chunks = 128
21-
chunk_bytes = int(size_mb * 1024 * 1024 / chunks)
22-
data = os.urandom(chunk_bytes)
20+
chunks = 128
21+
chunk_bytes = int(size_mb * 1024 * 1024 / chunks)
22+
data = os.urandom(chunk_bytes)
2323

24-
with open(file_path, 'wb') as f:
25-
for _ in range(chunks):
26-
f.write(data)
24+
with open(file_path, 'wb') as f:
25+
for _ in range(chunks):
26+
f.write(data)
2727

2828
class MockResponse():
2929
def __init__(self, text, status_code):

selfdrive/manager/process.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ def prepare(self) -> None:
199199
def start(self) -> None:
200200
# In case we only tried a non blocking stop we need to stop it before restarting
201201
if self.shutting_down:
202-
self.stop()
202+
self.stop()
203203

204204
if self.proc is not None:
205205
return
@@ -231,7 +231,7 @@ def prepare(self) -> None:
231231
def start(self) -> None:
232232
# In case we only tried a non blocking stop we need to stop it before restarting
233233
if self.shutting_down:
234-
self.stop()
234+
self.stop()
235235

236236
if self.proc is not None:
237237
return

selfdrive/monitoring/test_monitoring.py

+15-15
Original file line numberDiff line numberDiff line change
@@ -136,21 +136,21 @@ def test_biggest_comma_fan(self):
136136
# engaged, invisible driver, down to orange, driver touches wheel; then down to orange again, driver appears
137137
# - both actions should clear the alert, but momentary appearance should not
138138
def test_sometimes_transparent_commuter(self):
139-
_visible_time = np.random.choice([0.5, 10])
140-
ds_vector = always_no_face[:]*2
141-
interaction_vector = always_false[:]*2
142-
ds_vector[int((2*INVISIBLE_SECONDS_TO_ORANGE+1)/DT_DMON):int((2*INVISIBLE_SECONDS_TO_ORANGE+1+_visible_time)/DT_DMON)] = [msg_ATTENTIVE] * int(_visible_time/DT_DMON)
143-
interaction_vector[int((INVISIBLE_SECONDS_TO_ORANGE)/DT_DMON):int((INVISIBLE_SECONDS_TO_ORANGE+1)/DT_DMON)] = [True] * int(1/DT_DMON)
144-
events, _ = self._run_seq(ds_vector, interaction_vector, 2*always_true, 2*always_false)
145-
self.assertTrue(len(events[int(INVISIBLE_SECONDS_TO_ORANGE*0.5/DT_DMON)]) == 0)
146-
self.assertEqual(events[int((INVISIBLE_SECONDS_TO_ORANGE-0.1)/DT_DMON)].names[0], EventName.promptDriverUnresponsive)
147-
self.assertTrue(len(events[int((INVISIBLE_SECONDS_TO_ORANGE+0.1)/DT_DMON)]) == 0)
148-
if _visible_time == 0.5:
149-
self.assertEqual(events[int((INVISIBLE_SECONDS_TO_ORANGE*2+1-0.1)/DT_DMON)].names[0], EventName.promptDriverUnresponsive)
150-
self.assertEqual(events[int((INVISIBLE_SECONDS_TO_ORANGE*2+1+0.1+_visible_time)/DT_DMON)].names[0], EventName.preDriverUnresponsive)
151-
elif _visible_time == 10:
152-
self.assertEqual(events[int((INVISIBLE_SECONDS_TO_ORANGE*2+1-0.1)/DT_DMON)].names[0], EventName.promptDriverUnresponsive)
153-
self.assertTrue(len(events[int((INVISIBLE_SECONDS_TO_ORANGE*2+1+0.1+_visible_time)/DT_DMON)]) == 0)
139+
_visible_time = np.random.choice([0.5, 10])
140+
ds_vector = always_no_face[:]*2
141+
interaction_vector = always_false[:]*2
142+
ds_vector[int((2*INVISIBLE_SECONDS_TO_ORANGE+1)/DT_DMON):int((2*INVISIBLE_SECONDS_TO_ORANGE+1+_visible_time)/DT_DMON)] = [msg_ATTENTIVE] * int(_visible_time/DT_DMON)
143+
interaction_vector[int((INVISIBLE_SECONDS_TO_ORANGE)/DT_DMON):int((INVISIBLE_SECONDS_TO_ORANGE+1)/DT_DMON)] = [True] * int(1/DT_DMON)
144+
events, _ = self._run_seq(ds_vector, interaction_vector, 2*always_true, 2*always_false)
145+
self.assertTrue(len(events[int(INVISIBLE_SECONDS_TO_ORANGE*0.5/DT_DMON)]) == 0)
146+
self.assertEqual(events[int((INVISIBLE_SECONDS_TO_ORANGE-0.1)/DT_DMON)].names[0], EventName.promptDriverUnresponsive)
147+
self.assertTrue(len(events[int((INVISIBLE_SECONDS_TO_ORANGE+0.1)/DT_DMON)]) == 0)
148+
if _visible_time == 0.5:
149+
self.assertEqual(events[int((INVISIBLE_SECONDS_TO_ORANGE*2+1-0.1)/DT_DMON)].names[0], EventName.promptDriverUnresponsive)
150+
self.assertEqual(events[int((INVISIBLE_SECONDS_TO_ORANGE*2+1+0.1+_visible_time)/DT_DMON)].names[0], EventName.preDriverUnresponsive)
151+
elif _visible_time == 10:
152+
self.assertEqual(events[int((INVISIBLE_SECONDS_TO_ORANGE*2+1-0.1)/DT_DMON)].names[0], EventName.promptDriverUnresponsive)
153+
self.assertTrue(len(events[int((INVISIBLE_SECONDS_TO_ORANGE*2+1+0.1+_visible_time)/DT_DMON)]) == 0)
154154

155155
# engaged, invisible driver, down to red, driver appears and then touches wheel, then disengages/reengages
156156
# - only disengage will clear the alert

selfdrive/test/process_replay/compare_logs.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def save_log(dest, log_msgs, compress=True):
2525
dat = bz2.compress(dat)
2626

2727
with open(dest, "wb") as f:
28-
f.write(dat)
28+
f.write(dat)
2929

3030

3131
def remove_ignored_fields(msg, ignore):

selfdrive/test/process_replay/process_replay.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ def ublox_rcv_callback(msg):
231231
elif (msg_class, msg_id) in {(2, 1 * 16 + 5), (10, 9)}:
232232
return ["ubloxGnss"]
233233
else:
234-
return []
234+
return []
235235

236236

237237
CONFIGS = [

selfdrive/test/process_replay/regen.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ def replay_manager_state(s, msgs):
6161
rk = Ratekeeper(service_list[s].frequency, print_delay_threshold=None)
6262

6363
while True:
64-
new_m = messaging.new_message('managerState')
65-
new_m.managerState.processes = [{'name': name, 'running': True} for name in managed_processes]
66-
pm.send(s, new_m)
67-
rk.keep_time()
64+
new_m = messaging.new_message('managerState')
65+
new_m.managerState.processes = [{'name': name, 'running': True} for name in managed_processes]
66+
pm.send(s, new_m)
67+
rk.keep_time()
6868

6969

7070
def replay_device_state(s, msgs):

selfdrive/tombstoned.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,9 @@ def report_tombstone_apport(fn):
153153
# Try to find first entry in openpilot, fall back to first line
154154
for line in stacktrace_s:
155155
if "at selfdrive/" in line:
156-
crash_function = line
157-
found = True
158-
break
156+
crash_function = line
157+
found = True
158+
break
159159

160160
if not found:
161161
crash_function = stacktrace_s[1]

0 commit comments

Comments
 (0)