Skip to content

Commit 5861145

Browse files
authored
[lldb] fix(lldb/**.py): fix comparison to None (#94017)
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. Co-authored-by: Eisuke Kawashima <[email protected]>
1 parent fd35a92 commit 5861145

File tree

18 files changed

+26
-26
lines changed

18 files changed

+26
-26
lines changed

lldb/bindings/interface/SBBreakpointDocstrings.i

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ TestBreakpointIgnoreCount.py),::
3939
#lldbutil.print_stacktraces(process)
4040
from lldbutil import get_stopped_thread
4141
thread = get_stopped_thread(process, lldb.eStopReasonBreakpoint)
42-
self.assertTrue(thread != None, 'There should be a thread stopped due to breakpoint')
42+
self.assertTrue(thread is not None, 'There should be a thread stopped due to breakpoint')
4343
frame0 = thread.GetFrameAtIndex(0)
4444
frame1 = thread.GetFrameAtIndex(1)
4545
frame2 = thread.GetFrameAtIndex(2)

lldb/bindings/interface/SBDataExtensions.i

+4-4
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,19 @@ STRING_EXTENSION_OUTSIDE(SBData)
4040
lldbtarget = lldbdict['target']
4141
else:
4242
lldbtarget = None
43-
if target == None and lldbtarget != None and lldbtarget.IsValid():
43+
if target is None and lldbtarget is not None and lldbtarget.IsValid():
4444
target = lldbtarget
45-
if ptr_size == None:
45+
if ptr_size is None:
4646
if target and target.IsValid():
4747
ptr_size = target.addr_size
4848
else:
4949
ptr_size = 8
50-
if endian == None:
50+
if endian is None:
5151
if target and target.IsValid():
5252
endian = target.byte_order
5353
else:
5454
endian = lldbdict['eByteOrderLittle']
55-
if size == None:
55+
if size is None:
5656
if value > 2147483647:
5757
size = 8
5858
elif value < -2147483648:

lldb/docs/use/python.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,13 @@ later explanations:
7575
12: if root_word == word:
7676
13: return cur_path
7777
14: elif word < root_word:
78-
15: if left_child_ptr.GetValue() == None:
78+
15: if left_child_ptr.GetValue() is None:
7979
16: return ""
8080
17: else:
8181
18: cur_path = cur_path + "L"
8282
19: return DFS (left_child_ptr, word, cur_path)
8383
20: else:
84-
21: if right_child_ptr.GetValue() == None:
84+
21: if right_child_ptr.GetValue() is None:
8585
22: return ""
8686
23: else:
8787
24: cur_path = cur_path + "R"

lldb/examples/python/armv7_cortex_m_target_defintion.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ def get_reg_num(reg_num_dict, reg_name):
222222

223223
def get_target_definition():
224224
global g_target_definition
225-
if g_target_definition == None:
225+
if g_target_definition is None:
226226
g_target_definition = {}
227227
offset = 0
228228
for reg_info in armv7_register_infos:

lldb/packages/Python/lldbsuite/test/dotest.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747

4848
def is_exe(fpath):
4949
"""Returns true if fpath is an executable."""
50-
if fpath == None:
50+
if fpath is None:
5151
return False
5252
if sys.platform == "win32":
5353
if not fpath.endswith(".exe"):

lldb/packages/Python/lldbsuite/test/lldbtest.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ def pointer_size():
229229

230230
def is_exe(fpath):
231231
"""Returns true if fpath is an executable."""
232-
if fpath == None:
232+
if fpath is None:
233233
return False
234234
if sys.platform == "win32":
235235
if not fpath.endswith(".exe"):
@@ -2191,7 +2191,7 @@ def complete_from_to(self, str_input, patterns):
21912191
if num_matches == 0:
21922192
compare_string = str_input
21932193
else:
2194-
if common_match != None and len(common_match) > 0:
2194+
if common_match is not None and len(common_match) > 0:
21952195
compare_string = str_input + common_match
21962196
else:
21972197
compare_string = ""
@@ -2552,7 +2552,7 @@ def assertFailure(self, obj, error_str=None, msg=None):
25522552
if obj.Success():
25532553
self.fail(self._formatMessage(msg, "Error not in a fail state"))
25542554

2555-
if error_str == None:
2555+
if error_str is None:
25562556
return
25572557

25582558
error = obj.GetCString()

lldb/packages/Python/lldbsuite/test/lldbutil.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1594,11 +1594,11 @@ def set_actions_for_signal(
15941594
):
15951595
return_obj = lldb.SBCommandReturnObject()
15961596
command = "process handle {0}".format(signal_name)
1597-
if pass_action != None:
1597+
if pass_action is not None:
15981598
command += " -p {0}".format(pass_action)
1599-
if stop_action != None:
1599+
if stop_action is not None:
16001600
command += " -s {0}".format(stop_action)
1601-
if notify_action != None:
1601+
if notify_action is not None:
16021602
command += " -n {0}".format(notify_action)
16031603

16041604
testcase.dbg.GetCommandInterpreter().HandleCommand(command, return_obj)

lldb/packages/Python/lldbsuite/test/tools/intelpt/intelpt_testcase.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def traceStartProcess(
134134
self.assertSBError(trace.Start(configuration), error=error)
135135
else:
136136
command = "process trace start"
137-
if processBufferSizeLimit != None:
137+
if processBufferSizeLimit is not None:
138138
command += " -l " + str(processBufferSizeLimit)
139139
if enableTsc:
140140
command += " --tsc"

lldb/test/API/functionalities/breakpoint/address_breakpoints/TestBadAddressBreakpoints.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def address_breakpoints(self):
3232
for region_idx in range(regions.GetSize()):
3333
region = lldb.SBMemoryRegionInfo()
3434
regions.GetMemoryRegionAtIndex(region_idx, region)
35-
if illegal_address == None or region.GetRegionEnd() > illegal_address:
35+
if illegal_address is None or region.GetRegionEnd() > illegal_address:
3636
illegal_address = region.GetRegionEnd()
3737

3838
if illegal_address is not None:

lldb/test/API/functionalities/step_scripted/TestStepScripted.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def run_step(self, stop_others_value, run_mode, token):
126126
cmd = "thread step-scripted -C Steps.StepReportsStopOthers -k token -v %s" % (
127127
token
128128
)
129-
if run_mode != None:
129+
if run_mode is not None:
130130
cmd = cmd + " --run-mode %s" % (run_mode)
131131
if self.TraceOn():
132132
print(cmd)

lldb/test/API/functionalities/stop-on-sharedlibrary-load/TestStopOnSharedlibraryEvents.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def do_test(self, bkpt_modifier=None):
9999
backstop_bkpt_2.GetNumLocations(), 0, "Set our third breakpoint"
100100
)
101101

102-
if bkpt_modifier == None:
102+
if bkpt_modifier is None:
103103
process.Continue()
104104
self.assertState(
105105
process.GetState(), lldb.eStateStopped, "We didn't stop for the load"

lldb/test/API/lua_api/TestLuaAPI.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def killProcess():
115115
out, err = p.communicate(input=input)
116116
exitCode = p.wait()
117117
finally:
118-
if timerObject != None:
118+
if timerObject is not None:
119119
timerObject.cancel()
120120

121121
# Ensure the resulting output is always of string type.

lldb/test/API/macosx/thread_suspend/TestInternalThreadSuspension.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def suspended_thread_test(self):
9292
thread = lldb.SBThread()
9393
for thread in process.threads:
9494
th_name = thread.GetName()
95-
if th_name == None:
95+
if th_name is None:
9696
continue
9797
if "Look for me" in th_name:
9898
break

lldb/test/API/python_api/event/TestEvents.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ def wait_for_next_event(self, expected_state, test_shadow=False):
335335
if state == lldb.eStateStopped:
336336
restart = lldb.SBProcess.GetRestartedFromEvent(event)
337337

338-
if expected_state != None:
338+
if expected_state is not None:
339339
self.assertEqual(
340340
state, expected_state, "Primary thread got the correct event"
341341
)

lldb/test/API/python_api/process/read-mem-cstring/TestReadMemCString.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,4 @@ def test_read_memory_c_string(self):
6161
invalid_memory_str_addr, 2048, err
6262
)
6363
self.assertTrue(err.Fail())
64-
self.assertTrue(invalid_memory_string == "" or invalid_memory_string == None)
64+
self.assertTrue(invalid_memory_string == "" or invalid_memory_string is None)

lldb/test/API/python_api/type/TestTypeList.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def test(self):
132132
"my_type_is_named has a named type",
133133
)
134134
self.assertTrue(field.type.IsAggregateType())
135-
elif field.name == None:
135+
elif field.name is None:
136136
self.assertTrue(
137137
field.type.IsAnonymousType(), "Nameless type is not anonymous"
138138
)

lldb/test/API/python_api/was_interrupted/interruptible.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def __call__(self, debugger, args, exe_ctx, result):
4545
For the "check" case, it doesn't wait, but just returns whether there was
4646
an interrupt in force or not."""
4747

48-
if local_data == None:
48+
if local_data is None:
4949
result.SetError("local data was not set.")
5050
result.SetStatus(lldb.eReturnStatusFailed)
5151
return

lldb/test/Shell/lit.cfg.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def calculate_arch_features(arch_string):
145145
if config.lldb_enable_lzma:
146146
config.available_features.add("lzma")
147147

148-
if shutil.which("xz") != None:
148+
if shutil.which("xz") is not None:
149149
config.available_features.add("xz")
150150

151151
if config.lldb_system_debugserver:

0 commit comments

Comments
 (0)