Fix miscellaneous pylint warnings with no behavior change: - W0611: remove unused import struct - W0702: replace bare except with except Exception - C0325: remove superfluous parentheses after return - R1705: remove unnecessary elif after return - W0108: replace unnecessary lambda with int - R1714: merge comparisons with in operator - W0719: replace raise Exception with raise ValueError - C1802: use implicit boolean test instead of len() - C0121: use is None instead of == None - R1719: simplify if-expression to bool test - R1703: simplify if/else to assignment expression - W0612: remove unused variables (keybits, maskbits, lst) - replace unused loop variable with underscore
Signed-off-by: Minxi Hou <[email protected]> --- .../selftests/net/openvswitch/ovs-dpctl.py | 50 ++++++++----------- 1 file changed, 21 insertions(+), 29 deletions(-) diff --git a/tools/testing/selftests/net/openvswitch/ovs-dpctl.py b/tools/testing/selftests/net/openvswitch/ovs-dpctl.py index 3671fe16b5a7..5ce054768f48 100644 --- a/tools/testing/selftests/net/openvswitch/ovs-dpctl.py +++ b/tools/testing/selftests/net/openvswitch/ovs-dpctl.py @@ -11,7 +11,6 @@ import logging import math import multiprocessing import re -import struct import sys import time import types @@ -125,10 +124,7 @@ def parse_flags(flag_str, flag_vals): maskResult = int(digits, 0) while len(flag_str) > 0 and (flag_str[0] == "+" or flag_str[0] == "-"): - if flag_str[0] == "+": - setFlag = True - elif flag_str[0] == "-": - setFlag = False + setFlag = flag_str[0] == "+" flag_str = flag_str[1:] @@ -221,10 +217,9 @@ def convert_int(size): if not value: return 0, 0 - elif not mask: + if not mask: return int(value, 0), pow(2, size) - 1 - else: - return int(value, 0), int(mask, 0) + return int(value, 0), int(mask, 0) return convert_int_sized @@ -688,11 +683,11 @@ class ovsactions(nla): parsed = True else: actstr = actstr[len("drop"): ] - return (totallen - len(actstr)) + return totallen - len(actstr) elif parse_starts_block(actstr, r"^(\d+)", False, True): actstr, output = parse_extract_field( - actstr, None, r"(\d+)", lambda x: int(x), False, "0" + actstr, None, r"(\d+)", int, False, "0" ) self["attrs"].append(["OVS_ACTION_ATTR_OUTPUT", output]) parsed = True @@ -773,7 +768,6 @@ class ovsactions(nla): subacts = ovsactions() actstr = actstr[len("clone("):] parsedLen = subacts.parse(actstr) - lst = [] self["attrs"].append(("OVS_ACTION_ATTR_CLONE", subacts)) actstr = actstr[parsedLen:] parsed = True @@ -929,14 +923,14 @@ class ovsactions(nla): actstr = actstr[1:] if len(actstr) and actstr[0] == ")": - return (totallen - len(actstr)) + return totallen - len(actstr) actstr = actstr[strspn(actstr, ", ") :] if not parsed: raise ValueError(f"Action str: '{actstr}' not supported") - return (totallen - len(actstr)) + return totallen - len(actstr) class ovskey(nla): @@ -1020,8 +1014,6 @@ class ovskey(nla): if flowstr.startswith("("): flowstr = flowstr[1:] - keybits = b"" - maskbits = b"" for f in self.fields_map: if flowstr.startswith(f[1]): # the following assumes that the field looks @@ -1030,7 +1022,7 @@ class ovskey(nla): flowstr = flowstr[len(f[1]) + 1 :] splitchar = 0 for c in flowstr: - if c == "," or c == ")": + if c in (",", ")"): break splitchar += 1 data = flowstr[:splitchar] @@ -1587,7 +1579,7 @@ class ovskey(nla): for prefix, regex, typ, attr_name, mask_val, default_val, v46_flag in fields: flowstr, value = parse_extract_field(flowstr, prefix, regex, typ, False) if not attr_name: - raise Exception("Bad list value in tunnel fields") + raise ValueError("Bad list value in tunnel fields") if value is None and attr_name in forced_include: value = default_val @@ -1670,7 +1662,7 @@ class ovskey(nla): if not noprint: print_str += "," - if len(flagsattrs): + if flagsattrs: print_str += f"flags({'|'.join(flagsattrs)})" print_str += ")" return print_str @@ -2250,7 +2242,7 @@ class OvsDatapath(GenericNetlinkSocket): nproc = multiprocessing.cpu_count() procarray = [] - for i in range(1, nproc): + for _ in range(1, nproc): procarray += [int(p.epid)] msg["attrs"].append(["OVS_DP_ATTR_UPCALL_PID", procarray]) msg["attrs"].append(["OVS_DP_ATTR_USER_FEATURES", dpfeatures]) @@ -2335,26 +2327,26 @@ class OvsVport(GenericNetlinkSocket): def type_to_str(vport_type): if vport_type == OvsVport.OVS_VPORT_TYPE_NETDEV: return "netdev" - elif vport_type == OvsVport.OVS_VPORT_TYPE_INTERNAL: + if vport_type == OvsVport.OVS_VPORT_TYPE_INTERNAL: return "internal" - elif vport_type == OvsVport.OVS_VPORT_TYPE_GRE: + if vport_type == OvsVport.OVS_VPORT_TYPE_GRE: return "gre" - elif vport_type == OvsVport.OVS_VPORT_TYPE_VXLAN: + if vport_type == OvsVport.OVS_VPORT_TYPE_VXLAN: return "vxlan" - elif vport_type == OvsVport.OVS_VPORT_TYPE_GENEVE: + if vport_type == OvsVport.OVS_VPORT_TYPE_GENEVE: return "geneve" raise ValueError(f"Unknown vport type:{vport_type}") def str_to_type(vport_type): if vport_type == "netdev": return OvsVport.OVS_VPORT_TYPE_NETDEV - elif vport_type == "internal": + if vport_type == "internal": return OvsVport.OVS_VPORT_TYPE_INTERNAL - elif vport_type == "gre": + if vport_type == "gre": return OvsVport.OVS_VPORT_TYPE_GRE - elif vport_type == "vxlan": + if vport_type == "vxlan": return OvsVport.OVS_VPORT_TYPE_VXLAN - elif vport_type == "geneve": + if vport_type == "geneve": return OvsVport.OVS_VPORT_TYPE_GENEVE raise ValueError(f"Unknown vport type: '{vport_type}'") @@ -2463,7 +2455,7 @@ class OvsVport(GenericNetlinkSocket): msg["dpifindex"] = dpindex msg["attrs"].append(["OVS_VPORT_ATTR_NAME", vport_ifname]) - if p == None: + if p is None: p = self.upcall_packet else: self.upcall_packet = p @@ -3036,7 +3028,7 @@ def main(argv): return 1 rep = ovsflow.dump(rep["dpifindex"]) for flow in rep: - print(flow.dpstr(True if args.verbose > 0 else False)) + print(flow.dpstr(args.verbose > 0)) elif hasattr(args, "flbr"): rep = ovsdp.info(args.flbr, 0) if rep is None: -- 2.53.0

