[Lldb-commits] [lldb] [lldb] fix(lldb/**.py): fix comparison to None (PR #94017)
Eisuke Kawashima via lldb-commits
lldb-commits at lists.llvm.org
Sun Jun 23 05:16:38 PDT 2024
https://github.com/e-kwsm updated https://github.com/llvm/llvm-project/pull/94017
>From a10dbbe288bdb115df56ef60c48f9efbf6642bd3 Mon Sep 17 00:00:00 2001
From: Eisuke Kawashima <e-kwsm at users.noreply.github.com>
Date: Sat, 11 May 2024 23:57:11 +0900
Subject: [PATCH] fix(lldb/**.py): fix comparison to None
from PEP8 (https://peps.python.org/pep-0008/#programming-recommendations):
> Comparisons to singletons like None should always be done with is or
> is not, never the equality operators.
---
lldb/bindings/interface/SBBreakpointDocstrings.i | 2 +-
lldb/bindings/interface/SBDataExtensions.i | 8 ++++----
lldb/docs/use/python.rst | 4 ++--
lldb/examples/python/armv7_cortex_m_target_defintion.py | 2 +-
lldb/packages/Python/lldbsuite/test/dotest.py | 2 +-
lldb/packages/Python/lldbsuite/test/lldbtest.py | 6 +++---
lldb/packages/Python/lldbsuite/test/lldbutil.py | 6 +++---
.../lldbsuite/test/tools/intelpt/intelpt_testcase.py | 2 +-
.../address_breakpoints/TestBadAddressBreakpoints.py | 2 +-
.../API/functionalities/step_scripted/TestStepScripted.py | 2 +-
.../TestStopOnSharedlibraryEvents.py | 2 +-
lldb/test/API/lua_api/TestLuaAPI.py | 2 +-
.../macosx/thread_suspend/TestInternalThreadSuspension.py | 2 +-
lldb/test/API/python_api/event/TestEvents.py | 2 +-
.../process/read-mem-cstring/TestReadMemCString.py | 2 +-
lldb/test/API/python_api/type/TestTypeList.py | 2 +-
lldb/test/API/python_api/was_interrupted/interruptible.py | 2 +-
lldb/test/Shell/lit.cfg.py | 2 +-
18 files changed, 26 insertions(+), 26 deletions(-)
diff --git a/lldb/bindings/interface/SBBreakpointDocstrings.i b/lldb/bindings/interface/SBBreakpointDocstrings.i
index 74c139d5d9fb6..dca2819a9927b 100644
--- a/lldb/bindings/interface/SBBreakpointDocstrings.i
+++ b/lldb/bindings/interface/SBBreakpointDocstrings.i
@@ -39,7 +39,7 @@ TestBreakpointIgnoreCount.py),::
#lldbutil.print_stacktraces(process)
from lldbutil import get_stopped_thread
thread = get_stopped_thread(process, lldb.eStopReasonBreakpoint)
- self.assertTrue(thread != None, 'There should be a thread stopped due to breakpoint')
+ self.assertTrue(thread is not None, 'There should be a thread stopped due to breakpoint')
frame0 = thread.GetFrameAtIndex(0)
frame1 = thread.GetFrameAtIndex(1)
frame2 = thread.GetFrameAtIndex(2)
diff --git a/lldb/bindings/interface/SBDataExtensions.i b/lldb/bindings/interface/SBDataExtensions.i
index d980e79221c6d..ddea77a088dfa 100644
--- a/lldb/bindings/interface/SBDataExtensions.i
+++ b/lldb/bindings/interface/SBDataExtensions.i
@@ -40,19 +40,19 @@ STRING_EXTENSION_OUTSIDE(SBData)
lldbtarget = lldbdict['target']
else:
lldbtarget = None
- if target == None and lldbtarget != None and lldbtarget.IsValid():
+ if target is None and lldbtarget is not None and lldbtarget.IsValid():
target = lldbtarget
- if ptr_size == None:
+ if ptr_size is None:
if target and target.IsValid():
ptr_size = target.addr_size
else:
ptr_size = 8
- if endian == None:
+ if endian is None:
if target and target.IsValid():
endian = target.byte_order
else:
endian = lldbdict['eByteOrderLittle']
- if size == None:
+ if size is None:
if value > 2147483647:
size = 8
elif value < -2147483648:
diff --git a/lldb/docs/use/python.rst b/lldb/docs/use/python.rst
index 6183d6935d80e..d9c29d95708c1 100644
--- a/lldb/docs/use/python.rst
+++ b/lldb/docs/use/python.rst
@@ -75,13 +75,13 @@ later explanations:
12: if root_word == word:
13: return cur_path
14: elif word < root_word:
- 15: if left_child_ptr.GetValue() == None:
+ 15: if left_child_ptr.GetValue() is None:
16: return ""
17: else:
18: cur_path = cur_path + "L"
19: return DFS (left_child_ptr, word, cur_path)
20: else:
- 21: if right_child_ptr.GetValue() == None:
+ 21: if right_child_ptr.GetValue() is None:
22: return ""
23: else:
24: cur_path = cur_path + "R"
diff --git a/lldb/examples/python/armv7_cortex_m_target_defintion.py b/lldb/examples/python/armv7_cortex_m_target_defintion.py
index 42eaa39993dae..8225670f33e6b 100755
--- a/lldb/examples/python/armv7_cortex_m_target_defintion.py
+++ b/lldb/examples/python/armv7_cortex_m_target_defintion.py
@@ -222,7 +222,7 @@ def get_reg_num(reg_num_dict, reg_name):
def get_target_definition():
global g_target_definition
- if g_target_definition == None:
+ if g_target_definition is None:
g_target_definition = {}
offset = 0
for reg_info in armv7_register_infos:
diff --git a/lldb/packages/Python/lldbsuite/test/dotest.py b/lldb/packages/Python/lldbsuite/test/dotest.py
index 06acfb2f0756c..f14a00a2394b0 100644
--- a/lldb/packages/Python/lldbsuite/test/dotest.py
+++ b/lldb/packages/Python/lldbsuite/test/dotest.py
@@ -47,7 +47,7 @@
def is_exe(fpath):
"""Returns true if fpath is an executable."""
- if fpath == None:
+ if fpath is None:
return False
if sys.platform == "win32":
if not fpath.endswith(".exe"):
diff --git a/lldb/packages/Python/lldbsuite/test/lldbtest.py b/lldb/packages/Python/lldbsuite/test/lldbtest.py
index 1ad8ab6e6e462..db48a2a9c46c4 100644
--- a/lldb/packages/Python/lldbsuite/test/lldbtest.py
+++ b/lldb/packages/Python/lldbsuite/test/lldbtest.py
@@ -229,7 +229,7 @@ def pointer_size():
def is_exe(fpath):
"""Returns true if fpath is an executable."""
- if fpath == None:
+ if fpath is None:
return False
if sys.platform == "win32":
if not fpath.endswith(".exe"):
@@ -2191,7 +2191,7 @@ def complete_from_to(self, str_input, patterns):
if num_matches == 0:
compare_string = str_input
else:
- if common_match != None and len(common_match) > 0:
+ if common_match is not None and len(common_match) > 0:
compare_string = str_input + common_match
else:
compare_string = ""
@@ -2552,7 +2552,7 @@ def assertFailure(self, obj, error_str=None, msg=None):
if obj.Success():
self.fail(self._formatMessage(msg, "Error not in a fail state"))
- if error_str == None:
+ if error_str is None:
return
error = obj.GetCString()
diff --git a/lldb/packages/Python/lldbsuite/test/lldbutil.py b/lldb/packages/Python/lldbsuite/test/lldbutil.py
index 02ec65170f20c..629565b38ca1e 100644
--- a/lldb/packages/Python/lldbsuite/test/lldbutil.py
+++ b/lldb/packages/Python/lldbsuite/test/lldbutil.py
@@ -1594,11 +1594,11 @@ def set_actions_for_signal(
):
return_obj = lldb.SBCommandReturnObject()
command = "process handle {0}".format(signal_name)
- if pass_action != None:
+ if pass_action is not None:
command += " -p {0}".format(pass_action)
- if stop_action != None:
+ if stop_action is not None:
command += " -s {0}".format(stop_action)
- if notify_action != None:
+ if notify_action is not None:
command += " -n {0}".format(notify_action)
testcase.dbg.GetCommandInterpreter().HandleCommand(command, return_obj)
diff --git a/lldb/packages/Python/lldbsuite/test/tools/intelpt/intelpt_testcase.py b/lldb/packages/Python/lldbsuite/test/tools/intelpt/intelpt_testcase.py
index fd1eb64219585..f1b7d7c33bf07 100644
--- a/lldb/packages/Python/lldbsuite/test/tools/intelpt/intelpt_testcase.py
+++ b/lldb/packages/Python/lldbsuite/test/tools/intelpt/intelpt_testcase.py
@@ -134,7 +134,7 @@ def traceStartProcess(
self.assertSBError(trace.Start(configuration), error=error)
else:
command = "process trace start"
- if processBufferSizeLimit != None:
+ if processBufferSizeLimit is not None:
command += " -l " + str(processBufferSizeLimit)
if enableTsc:
command += " --tsc"
diff --git a/lldb/test/API/functionalities/breakpoint/address_breakpoints/TestBadAddressBreakpoints.py b/lldb/test/API/functionalities/breakpoint/address_breakpoints/TestBadAddressBreakpoints.py
index d120692e4d6e6..3674a8c233c8d 100644
--- a/lldb/test/API/functionalities/breakpoint/address_breakpoints/TestBadAddressBreakpoints.py
+++ b/lldb/test/API/functionalities/breakpoint/address_breakpoints/TestBadAddressBreakpoints.py
@@ -32,7 +32,7 @@ def address_breakpoints(self):
for region_idx in range(regions.GetSize()):
region = lldb.SBMemoryRegionInfo()
regions.GetMemoryRegionAtIndex(region_idx, region)
- if illegal_address == None or region.GetRegionEnd() > illegal_address:
+ if illegal_address is None or region.GetRegionEnd() > illegal_address:
illegal_address = region.GetRegionEnd()
if illegal_address is not None:
diff --git a/lldb/test/API/functionalities/step_scripted/TestStepScripted.py b/lldb/test/API/functionalities/step_scripted/TestStepScripted.py
index 9891a9c23b50c..53901718019f9 100644
--- a/lldb/test/API/functionalities/step_scripted/TestStepScripted.py
+++ b/lldb/test/API/functionalities/step_scripted/TestStepScripted.py
@@ -126,7 +126,7 @@ def run_step(self, stop_others_value, run_mode, token):
cmd = "thread step-scripted -C Steps.StepReportsStopOthers -k token -v %s" % (
token
)
- if run_mode != None:
+ if run_mode is not None:
cmd = cmd + " --run-mode %s" % (run_mode)
if self.TraceOn():
print(cmd)
diff --git a/lldb/test/API/functionalities/stop-on-sharedlibrary-load/TestStopOnSharedlibraryEvents.py b/lldb/test/API/functionalities/stop-on-sharedlibrary-load/TestStopOnSharedlibraryEvents.py
index 58205553154bf..f68eb4196c125 100644
--- a/lldb/test/API/functionalities/stop-on-sharedlibrary-load/TestStopOnSharedlibraryEvents.py
+++ b/lldb/test/API/functionalities/stop-on-sharedlibrary-load/TestStopOnSharedlibraryEvents.py
@@ -99,7 +99,7 @@ def do_test(self, bkpt_modifier=None):
backstop_bkpt_2.GetNumLocations(), 0, "Set our third breakpoint"
)
- if bkpt_modifier == None:
+ if bkpt_modifier is None:
process.Continue()
self.assertState(
process.GetState(), lldb.eStateStopped, "We didn't stop for the load"
diff --git a/lldb/test/API/lua_api/TestLuaAPI.py b/lldb/test/API/lua_api/TestLuaAPI.py
index 4c9a5d9672c4c..065de61ad6577 100644
--- a/lldb/test/API/lua_api/TestLuaAPI.py
+++ b/lldb/test/API/lua_api/TestLuaAPI.py
@@ -115,7 +115,7 @@ def killProcess():
out, err = p.communicate(input=input)
exitCode = p.wait()
finally:
- if timerObject != None:
+ if timerObject is not None:
timerObject.cancel()
# Ensure the resulting output is always of string type.
diff --git a/lldb/test/API/macosx/thread_suspend/TestInternalThreadSuspension.py b/lldb/test/API/macosx/thread_suspend/TestInternalThreadSuspension.py
index 1b33494cc5206..b41c2ae0976a2 100644
--- a/lldb/test/API/macosx/thread_suspend/TestInternalThreadSuspension.py
+++ b/lldb/test/API/macosx/thread_suspend/TestInternalThreadSuspension.py
@@ -92,7 +92,7 @@ def suspended_thread_test(self):
thread = lldb.SBThread()
for thread in process.threads:
th_name = thread.GetName()
- if th_name == None:
+ if th_name is None:
continue
if "Look for me" in th_name:
break
diff --git a/lldb/test/API/python_api/event/TestEvents.py b/lldb/test/API/python_api/event/TestEvents.py
index a15f4357f4f5f..d8d3dd2d2b01b 100644
--- a/lldb/test/API/python_api/event/TestEvents.py
+++ b/lldb/test/API/python_api/event/TestEvents.py
@@ -335,7 +335,7 @@ def wait_for_next_event(self, expected_state, test_shadow=False):
if state == lldb.eStateStopped:
restart = lldb.SBProcess.GetRestartedFromEvent(event)
- if expected_state != None:
+ if expected_state is not None:
self.assertEqual(
state, expected_state, "Primary thread got the correct event"
)
diff --git a/lldb/test/API/python_api/process/read-mem-cstring/TestReadMemCString.py b/lldb/test/API/python_api/process/read-mem-cstring/TestReadMemCString.py
index f664a18ebfa3d..108487b08bb00 100644
--- a/lldb/test/API/python_api/process/read-mem-cstring/TestReadMemCString.py
+++ b/lldb/test/API/python_api/process/read-mem-cstring/TestReadMemCString.py
@@ -61,4 +61,4 @@ def test_read_memory_c_string(self):
invalid_memory_str_addr, 2048, err
)
self.assertTrue(err.Fail())
- self.assertTrue(invalid_memory_string == "" or invalid_memory_string == None)
+ self.assertTrue(invalid_memory_string == "" or invalid_memory_string is None)
diff --git a/lldb/test/API/python_api/type/TestTypeList.py b/lldb/test/API/python_api/type/TestTypeList.py
index b028929eea442..bc4d00c17c555 100644
--- a/lldb/test/API/python_api/type/TestTypeList.py
+++ b/lldb/test/API/python_api/type/TestTypeList.py
@@ -132,7 +132,7 @@ def test(self):
"my_type_is_named has a named type",
)
self.assertTrue(field.type.IsAggregateType())
- elif field.name == None:
+ elif field.name is None:
self.assertTrue(
field.type.IsAnonymousType(), "Nameless type is not anonymous"
)
diff --git a/lldb/test/API/python_api/was_interrupted/interruptible.py b/lldb/test/API/python_api/was_interrupted/interruptible.py
index 4e7437d768d26..37999979e1a7f 100644
--- a/lldb/test/API/python_api/was_interrupted/interruptible.py
+++ b/lldb/test/API/python_api/was_interrupted/interruptible.py
@@ -45,7 +45,7 @@ def __call__(self, debugger, args, exe_ctx, result):
For the "check" case, it doesn't wait, but just returns whether there was
an interrupt in force or not."""
- if local_data == None:
+ if local_data is None:
result.SetError("local data was not set.")
result.SetStatus(lldb.eReturnStatusFailed)
return
diff --git a/lldb/test/Shell/lit.cfg.py b/lldb/test/Shell/lit.cfg.py
index e24f3fbb4d931..d764cfa20ea83 100644
--- a/lldb/test/Shell/lit.cfg.py
+++ b/lldb/test/Shell/lit.cfg.py
@@ -145,7 +145,7 @@ def calculate_arch_features(arch_string):
if config.lldb_enable_lzma:
config.available_features.add("lzma")
-if shutil.which("xz") != None:
+if shutil.which("xz") is not None:
config.available_features.add("xz")
if config.lldb_system_debugserver:
More information about the lldb-commits
mailing list