From: Minxi Hou <houminxi@gmail.com>
To: netdev@vger.kernel.org
Cc: aconole@redhat.com, davem@davemloft.net, dev@openvswitch.org,
echaudro@redhat.com, edumazet@google.com, i.maximets@ovn.org,
kuba@kernel.org, linux-kernel@vger.kernel.org,
linux-kselftest@vger.kernel.org, pabeni@redhat.com,
shuah@kernel.org, horms@kernel.org,
Minxi Hou <houminxi@gmail.com>
Subject: [PATCH 2/4] selftests: openvswitch: fix misc pylint warnings in ovs-dpctl.py
Date: Sat, 5 Sep 2026 06:40:24 -0400 [thread overview]
Message-ID: <20260905104026.3776396-3-houminxi@gmail.com> (raw)
In-Reply-To: <20260905104026.3776396-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 (3)
- R1705: remove unnecessary elif after return (3)
- 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>
---
base-commit: 9eab111e765729e93087ff86a2ec9b2ae42d0fa5
.../selftests/net/openvswitch/ovs-dpctl.py | 44 ++++++++-----------
1 file changed, 19 insertions(+), 25 deletions(-)
diff --git a/tools/testing/selftests/net/openvswitch/ovs-dpctl.py b/tools/testing/selftests/net/openvswitch/ovs-dpctl.py
index 9cd0d8f0ab23..6a02810fe4ea 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
@@ -705,11 +700,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
@@ -761,12 +756,12 @@ class ovsactions(nla):
vid = int(v, 0)
if vid < 0 or vid > 0xFFF:
raise ValueError(
- f"push_vlan(): vid={int(vid)} out of range (0-4095)")
+ f"push_vlan(): vid={vid} out of range (0-4095)")
elif k == "pcp":
pcp = int(v, 0)
if pcp < 0 or pcp > 7:
raise ValueError(
- f"push_vlan(): pcp={int(pcp)} out of range (0-7)")
+ f"push_vlan(): pcp={pcp} out of range (0-7)")
elif k == "tpid":
tpid = int(v, 0)
if tpid < 0 or tpid > 0xFFFF:
@@ -804,7 +799,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
@@ -960,14 +954,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)
# pyroute2 resolves nla_map types via getattr(self, name).
@@ -1057,8 +1051,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
@@ -1067,7 +1059,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]
@@ -1631,7 +1623,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
@@ -1714,7 +1706,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
@@ -2304,7 +2296,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])
@@ -2379,15 +2371,17 @@ 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"
+
raise ValueError(f"Unknown vport type:{int(vport_type)}")
def str_to_type(vport_type):
if vport_type in ["netdev", "gre", "vxlan", "geneve"]:
return OvsVport.OVS_VPORT_TYPE_NETDEV
- elif vport_type == "internal":
+ if vport_type == "internal":
return OvsVport.OVS_VPORT_TYPE_INTERNAL
+
raise ValueError(f"Unknown vport type: '{vport_type}'")
def __init__(self, packet=OvsPacket()):
@@ -2482,7 +2476,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
@@ -3068,7 +3062,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.55.0
next prev parent reply other threads:[~2026-09-05 10:40 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-05 10:40 [PATCH net-next 0/4] selftests: openvswitch: pylint cleanup of ovs-dpctl.py Minxi Hou
2026-09-05 10:40 ` [PATCH 1/4] selftests: openvswitch: convert %-formatting to f-strings Minxi Hou
2026-09-09 12:42 ` netdev-bot+sashiko
2026-09-05 10:40 ` Minxi Hou [this message]
2026-09-09 12:42 ` [PATCH 2/4] selftests: openvswitch: fix misc pylint warnings in ovs-dpctl.py netdev-bot+sashiko
2026-09-05 10:40 ` [PATCH 3/4] selftests: openvswitch: add missing docstrings " Minxi Hou
2026-09-09 12:42 ` netdev-bot+sashiko
2026-09-05 10:40 ` [PATCH 4/4] selftests: openvswitch: suppress pylint complexity warnings Minxi Hou
2026-09-09 12:42 ` netdev-bot+sashiko
2026-09-06 8:55 ` [PATCH net-next 0/4] selftests: openvswitch: pylint cleanup of ovs-dpctl.py Minxi Hou
2026-09-08 17:04 ` [net-next,0/4] " Minxi Hou
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=20260905104026.3776396-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=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.