all: Fix Python comparison to None and True, and use "not in".

These are basic PEP8 recommendations.
pull/10979/head
Christian Clauss 2023-03-08 16:17:54 +01:00 zatwierdzone przez Damien George
rodzic f3a596db7d
commit 4376c969f6
6 zmienionych plików z 12 dodań i 12 usunięć

Wyświetl plik

@ -45,7 +45,7 @@ def transfer_file(args):
if "250" in ftp.cwd("/flash"):
if not ftp_directory_exists(ftp, "sys"):
print("/flash/sys directory does not exist")
if not "550" in ftp.mkd("sys"):
if "550" not in ftp.mkd("sys"):
print("/flash/sys directory created")
else:
print("Error: cannot create /flash/sys directory")

Wyświetl plik

@ -120,13 +120,13 @@ class PowerUp3:
return int(self.char_batt_lvl.read()[0])
def speed(self, new_speed=None):
if new_speed == None:
if new_speed is None:
return int(self.char_control_speed.read()[0])
else:
self.char_control_speed.write(bytearray([new_speed]))
def angle(self, new_angle=None):
if new_angle == None:
if new_angle is None:
return int(self.char_control_angle.read()[0])
else:
self.char_control_angle.write(bytearray([new_angle]))

Wyświetl plik

@ -116,7 +116,7 @@ class PIOASMEmit:
if label is None:
label = 0
else:
if not label in self.labels:
if label not in self.labels:
raise PIOASMError("unknown label {}".format(label))
label = self.labels[label]
self.prog[_PROG_DATA].append(instr | label)

Wyświetl plik

@ -94,7 +94,7 @@ def compute_pll2(hse, sys, relax_pll48):
fallback = None
for P in mcu.range_p:
# VCO_OUT must be between 192MHz and 432MHz
if not sys * P in mcu.range_vco_out:
if sys * P not in mcu.range_vco_out:
continue
NbyM = float(sys * P) / hse # float for Python 2
# scan M

Wyświetl plik

@ -122,9 +122,9 @@ def do_filesystem(state, args):
if command == "cat":
# Don't be verbose by default when using cat, so output can be
# redirected to something.
verbose = args.verbose == True
verbose = args.verbose is True
else:
verbose = args.verbose != False
verbose = args.verbose is not False
if command == "cp" and args.recursive:
if paths[-1] != ":":

Wyświetl plik

@ -85,9 +85,9 @@ def convert_from_uf2(buf):
if datalen > 476:
assert False, "Invalid UF2 data size at " + ptr
newaddr = hd[3]
if (hd[2] & 0x2000) and (currfamilyid == None):
if (hd[2] & 0x2000) and (currfamilyid is None):
currfamilyid = hd[7]
if curraddr == None or ((hd[2] & 0x2000) and hd[7] != currfamilyid):
if curraddr is None or ((hd[2] & 0x2000) and hd[7] != currfamilyid):
currfamilyid = hd[7]
curraddr = newaddr
if familyid == 0x0 or familyid == hd[7]:
@ -111,7 +111,7 @@ def convert_from_uf2(buf):
families_found[hd[7]] = newaddr
else:
families_found[hd[7]] = newaddr
if prev_flag == None:
if prev_flag is None:
prev_flag = hd[2]
if prev_flag != hd[2]:
all_flags_same = False
@ -234,7 +234,7 @@ def convert_from_hex_to_uf2(buf):
break
elif tp == 0:
addr = upper + ((rec[1] << 8) | rec[2])
if appstartaddr == None:
if appstartaddr is None:
appstartaddr = addr
i = 4
while i < len(rec) - 1:
@ -419,7 +419,7 @@ def main():
)
if args.convert or ext != "uf2":
drives = []
if args.output == None:
if args.output is None:
args.output = "flash." + ext
else:
drives = get_drives()