[PATCH] scripts: use is None instead of == None

From: Elijah Conners
Date: Thu Jun 16 2022 - 01:38:39 EST


In compaction-times.py, exported-sql-viewer.py, mem-phys-addr.py,
net_dropmonitor.py, kunit.py, and tdc.py, the None object is checked
against various variables using equality. This is 50% slower than using
an identity operator, since using equality invokes the __eq__ method.
Checking identity in this case is also much better form.

Signed-off-by: Elijah Conners <business@xxxxxxxxxxxxxx>
---
tools/perf/scripts/python/compaction-times.py | 2 +-
tools/perf/scripts/python/exported-sql-viewer.py | 2 +-
tools/perf/scripts/python/mem-phys-addr.py | 2 +-
tools/perf/scripts/python/net_dropmonitor.py | 2 +-
tools/testing/kunit/kunit.py | 2 +-
tools/testing/selftests/tc-testing/tdc.py | 2 +-
6 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/tools/perf/scripts/python/compaction-times.py b/tools/perf/scripts/python/compaction-times.py
index 2560a042dc6f..790cc58214a9 100644
--- a/tools/perf/scripts/python/compaction-times.py
+++ b/tools/perf/scripts/python/compaction-times.py
@@ -31,7 +31,7 @@ class comm_filter:

def filter(self, pid, comm):
m = self.re.search(comm)
- return m == None or m.group() == ""
+ return m is None or m.group() == ""

class pid_filter:
def __init__(self, low, high):
diff --git a/tools/perf/scripts/python/exported-sql-viewer.py b/tools/perf/scripts/python/exported-sql-viewer.py
index 13f2d8a81610..28b53739746f 100755
--- a/tools/perf/scripts/python/exported-sql-viewer.py
+++ b/tools/perf/scripts/python/exported-sql-viewer.py
@@ -452,7 +452,7 @@ class FindBar():
index = self.textbox.currentIndex()
data = self.textbox.itemData(index)
# Store the pattern in the combo box to keep it with the text value
- if data == None:
+ if data is None:
self.textbox.setItemData(index, pattern)
else:
self.pattern.setChecked(data)
diff --git a/tools/perf/scripts/python/mem-phys-addr.py b/tools/perf/scripts/python/mem-phys-addr.py
index 1f332e72b9b0..5891a4df69aa 100644
--- a/tools/perf/scripts/python/mem-phys-addr.py
+++ b/tools/perf/scripts/python/mem-phys-addr.py
@@ -95,6 +95,6 @@ def process_event(param_dict):
phys_addr = sample["phys_addr"]

global event_name
- if event_name == None:
+ if event_name is None:
event_name = name
load_mem_type_cnt[find_memory_type(phys_addr)] += 1
diff --git a/tools/perf/scripts/python/net_dropmonitor.py b/tools/perf/scripts/python/net_dropmonitor.py
index 101059971738..cd9488f11e03 100755
--- a/tools/perf/scripts/python/net_dropmonitor.py
+++ b/tools/perf/scripts/python/net_dropmonitor.py
@@ -55,7 +55,7 @@ def print_drop_table():
print("%25s %25s %25s" % ("LOCATION", "OFFSET", "COUNT"))
for i in drop_log.keys():
(sym, off) = get_sym(i)
- if sym == None:
+ if sym is None:
sym = i
print("%25s %25s %25s" % (sym, off, drop_log[i]))

diff --git a/tools/testing/kunit/kunit.py b/tools/testing/kunit/kunit.py
index 9274c6355809..6195e091d22d 100755
--- a/tools/testing/kunit/kunit.py
+++ b/tools/testing/kunit/kunit.py
@@ -496,7 +496,7 @@ def main(argv, linux=None):
if result.status != KunitStatus.SUCCESS:
sys.exit(1)
elif cli_args.subcommand == 'parse':
- if cli_args.file == None:
+ if cli_args.file is None:
sys.stdin.reconfigure(errors='backslashreplace') # pytype: disable=attribute-error
kunit_output = sys.stdin
else:
diff --git a/tools/testing/selftests/tc-testing/tdc.py b/tools/testing/selftests/tc-testing/tdc.py
index ee22e3447ec7..f1840023283a 100755
--- a/tools/testing/selftests/tc-testing/tdc.py
+++ b/tools/testing/selftests/tc-testing/tdc.py
@@ -355,7 +355,7 @@ def test_runner(pm, args, filtered_tests):
print('give test rig 2 seconds to stabilize')
time.sleep(2)
for tidx in testlist:
- if "flower" in tidx["category"] and args.device == None:
+ if "flower" in tidx["category"] and args.device is None:
errmsg = "Tests using the DEV2 variable must define the name of a "
errmsg += "physical NIC with the -d option when running tdc.\n"
errmsg += "Test has been skipped."
--
2.25.1