From: Minxi Hou <houminxi@gmail.com>
To: netdev@vger.kernel.org
Cc: dev@openvswitch.org, linux-kselftest@vger.kernel.org,
linux-kernel@vger.kernel.org, aconole@redhat.com,
echaudro@redhat.com, i.maximets@ovn.org, i.maximets@redhat.com,
davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
pabeni@redhat.com, horms@kernel.org, shuah@kernel.org,
Minxi Hou <houminxi@gmail.com>
Subject: [PATCH net-next 2/5] selftests: openvswitch: fix misc pylint warnings in ovs-dpctl.py
Date: Wed, 13 May 2026 20:12:37 +0800 [thread overview]
Message-ID: <20260513121240.2590767-3-houminxi@gmail.com> (raw)
In-Reply-To: <20260513121240.2590767-1-houminxi@gmail.com>
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 <houminxi@gmail.com>
---
.../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
next prev parent reply other threads:[~2026-05-13 12:13 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-13 12:12 [PATCH net-next 0/5] selftests: openvswitch: pylint cleanup for ovs-dpctl.py Minxi Hou
2026-05-13 12:12 ` [PATCH net-next 1/5] selftests: openvswitch: convert %-formatting to f-strings Minxi Hou
2026-05-13 12:12 ` Minxi Hou [this message]
2026-05-13 12:12 ` [PATCH net-next 3/5] selftests: openvswitch: rename classes and variables in ovs-dpctl.py Minxi Hou
2026-05-13 12:12 ` [PATCH net-next 4/5] selftests: openvswitch: add missing docstrings " Minxi Hou
2026-05-13 12:12 ` [PATCH net-next 5/5] selftests: openvswitch: suppress pylint complexity warnings Minxi Hou
2026-05-13 12:47 ` [PATCH net-next 0/5] selftests: openvswitch: pylint cleanup for ovs-dpctl.py Minxi Hou
2026-05-13 15:05 ` Aaron Conole
2026-05-15 6:53 ` Aaron Conole
2026-05-15 8:47 ` 侯敏熙
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260513121240.2590767-3-houminxi@gmail.com \
--to=houminxi@gmail.com \
--cc=aconole@redhat.com \
--cc=davem@davemloft.net \
--cc=dev@openvswitch.org \
--cc=echaudro@redhat.com \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=i.maximets@ovn.org \
--cc=i.maximets@redhat.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=shuah@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.