Skip to content

fix(python): fix comparison to None #91857

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions bolt/docs/generate_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def parse_bolt_options(output):
cleaned_line = line.strip()

if cleaned_line.casefold() in map(str.casefold, section_headers):
if prev_section != None: # Save last option from prev section
if prev_section is not None: # Save last option from prev section
add_info(sections, current_section, option, description)
option, description = None, []

Expand Down Expand Up @@ -76,7 +76,7 @@ def parse_bolt_options(output):
description = [descr]
if option.startswith("--print") or option.startswith("--time"):
current_section = "BOLT printing options:"
elif prev_section != None:
elif prev_section is not None:
current_section = prev_section
continue

Expand Down
2 changes: 1 addition & 1 deletion bolt/test/perf2bolt/lit.local.cfg
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import shutil

if shutil.which("perf") != None:
if shutil.which("perf") is not None:
config.available_features.add("perf")
Original file line number Diff line number Diff line change
Expand Up @@ -1071,7 +1071,7 @@ bool IdentifierNamingCheck::isParamInMainLikeFunction(
if (!IsIntType(FDecl->parameters()[0]->getType()))
return false;
MainType Type = IsCharPtrPtr(FDecl->parameters()[1]->getType());
if (Type == None)
if (Type is None)
return false;
if (FDecl->getNumParams() == 3 &&
IsCharPtrPtr(FDecl->parameters()[2]->getType()) != Type)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def get_checkers(checkers_td, checkers_rst):
parent_package_ = package["ParentPackage"]
hidden = (checker["Hidden"] != 0) or (package["Hidden"] != 0)

while parent_package_ != None:
while parent_package_ is not None:
parent_package = table_entries[parent_package_["def"]]
checker_package_prefix = (
parent_package["PackageName"] + "." + checker_package_prefix
Expand Down
8 changes: 4 additions & 4 deletions clang/docs/DebuggingCoroutines.rst
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ So we can use the ``continuation`` field to construct the asynchronous stack:
self.coro_frame = coro_frame
self.resume_func = dereference(self.coro_frame.resume_addr)
self.resume_func_block = gdb.block_for_pc(self.resume_func)
if self.resume_func_block == None:
if self.resume_func_block is None:
raise Exception('Not stackless coroutine.')
self.line_info = gdb.find_pc_line(self.resume_func)

Expand Down Expand Up @@ -543,8 +543,8 @@ So we can use the ``continuation`` field to construct the asynchronous stack:
self.function_name = f

def __str__(self, shift = 2):
addr = "" if self.address() == None else '%#x' % self.address() + " in "
location = "" if self.filename() == None else " at " + self.filename() + ":" + str(self.line())
addr = "" if self.address() is None else '%#x' % self.address() + " in "
location = "" if self.filename() is None else " at " + self.filename() + ":" + str(self.line())
return addr + self.function() + " " + str([str(args) for args in self.frame_args()]) + location

class CoroutineFilter:
Expand Down Expand Up @@ -598,7 +598,7 @@ So we can use the ``continuation`` field to construct the asynchronous stack:

addr = int(argv[0], 16)
block = gdb.block_for_pc(long(cast_addr2long_pointer(addr).dereference()))
if block == None:
if block is None:
print "block " + str(addr) + " is none."
return

Expand Down
2 changes: 1 addition & 1 deletion clang/tools/include-mapping/gen_std.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def GetCCompatibilitySymbols(symbol):
# Introduce two more entries, both in the global namespace, one using the
# C++-compat header and another using the C header.
results = []
if symbol.namespace != None:
if symbol.namespace is not None:
# avoid printing duplicated entries, for C macros!
results.append(cppreference_parser.Symbol(symbol.name, None, [header]))
c_header = "<" + header[2:-1] + ".h>" # <cstdio> => <stdio.h>
Expand Down
2 changes: 1 addition & 1 deletion clang/utils/check_cfc/obj_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def first_diff(a, b, fromfile, tofile):
first_diff_idx = idx
break

if first_diff_idx == None:
if first_diff_idx is None:
# No difference
return None

Expand Down
2 changes: 1 addition & 1 deletion clang/utils/module-deps-to-rsp.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def main():

if args.module_name:
cmd = findModule(args.module_name, full_deps)["command-line"]
elif args.tu_index != None:
elif args.tu_index is not None:
tu = full_deps.translation_units[args.tu_index]
cmd = tu["commands"][args.tu_cmd_index]["command-line"]

Expand Down
2 changes: 1 addition & 1 deletion compiler-rt/test/asan/lit.cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

def get_required_attr(config, attr_name):
attr_value = getattr(config, attr_name, None)
if attr_value == None:
if attr_value is None:
lit_config.fatal(
"No attribute %r in test configuration! You may need to run "
"tests from your build directory or add this attribute "
Expand Down
2 changes: 1 addition & 1 deletion compiler-rt/test/builtins/Unit/lit.cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

def get_required_attr(config, attr_name):
attr_value = getattr(config, attr_name, None)
if attr_value == None:
if attr_value is None:
lit_config.fatal(
"No attribute %r in test configuration! You may need to run "
"tests from your build directory or add this attribute "
Expand Down
2 changes: 1 addition & 1 deletion compiler-rt/test/ctx_profile/lit.cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

def get_required_attr(config, attr_name):
attr_value = getattr(config, attr_name, None)
if attr_value == None:
if attr_value is None:
lit_config.fatal(
"No attribute %r in test configuration! You may need to run "
"tests from your build directory or add this attribute "
Expand Down
2 changes: 1 addition & 1 deletion compiler-rt/test/lsan/lit.common.cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

def get_required_attr(config, attr_name):
attr_value = getattr(config, attr_name, None)
if attr_value == None:
if attr_value is None:
lit_config.fatal(
"No attribute %r in test configuration! You may need to run "
"tests from your build directory or add this attribute "
Expand Down
2 changes: 1 addition & 1 deletion compiler-rt/test/memprof/lit.cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

def get_required_attr(config, attr_name):
attr_value = getattr(config, attr_name, None)
if attr_value == None:
if attr_value is None:
lit_config.fatal(
"No attribute %r in test configuration! You may need to run "
"tests from your build directory or add this attribute "
Expand Down
2 changes: 1 addition & 1 deletion compiler-rt/test/profile/lit.cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

def get_required_attr(config, attr_name):
attr_value = getattr(config, attr_name, None)
if attr_value == None:
if attr_value is None:
lit_config.fatal(
"No attribute %r in test configuration! You may need to run "
"tests from your build directory or add this attribute "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
elif arg == "-o":
output = args.pop(0)

if output == None:
if output is None:
print("No output file name!")
sys.exit(1)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
elif arg == "-o":
output = args.pop(0)

if output == None:
if output is None:
print("No output file name!")
sys.exit(1)

Expand Down
2 changes: 1 addition & 1 deletion compiler-rt/test/ubsan/lit.common.cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

def get_required_attr(config, attr_name):
attr_value = getattr(config, attr_name, None)
if attr_value == None:
if attr_value is None:
lit_config.fatal(
"No attribute %r in test configuration! You may need to run "
"tests from your build directory or add this attribute "
Expand Down
2 changes: 1 addition & 1 deletion compiler-rt/test/ubsan_minimal/lit.common.cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

def get_required_attr(config, attr_name):
attr_value = getattr(config, attr_name, None)
if attr_value == None:
if attr_value is None:
lit_config.fatal(
"No attribute %r in test configuration! You may need to run "
"tests from your build directory or add this attribute "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def _build_command(

def label_to_line(label_name: str) -> int:
line = labels.get(label_name, None)
if line != None:
if line is not None:
return line
raise format_unresolved_label_err(label_name, raw_text, path.base, lineno)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def __init__(
self.finish_on_remove = finish_on_remove

def has_conditions(self):
return self.expression != None
return self.expression is not None

def get_conditional_expression_list(self):
conditional_list = []
Expand All @@ -76,7 +76,7 @@ def add_hit(self):
self.current_hit_count += 1

def should_be_removed(self):
if self.max_hit_count == None:
if self.max_hit_count is None:
return False
return self.current_hit_count >= self.max_hit_count

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def update_step_watches(step_info, watches, commands):
for watch in towatch:
loc = step_info.current_location
if (
loc.path != None
loc.path is not None
and os.path.exists(loc.path)
and os.path.samefile(watch.path, loc.path)
and have_hit_line(watch, loc)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def handle_debugger_tool_options(context, defaults): # noqa
if options.debugger == "lldb":
_warn_meaningless_option(context, "--show-debugger")

if options.source_root_dir != None:
if options.source_root_dir is not None:
if not os.path.isabs(options.source_root_dir):
raise ToolArgumentError(
f'<d>--source-root-dir: expected absolute path, got</> <r>"{options.source_root_dir}"</>'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def delete_breakpoints(self, ids):
for bp in self._debugger.Breakpoints:
# We're looking at the user-set breakpoints so there should be no
# Parent.
assert bp.Parent == None
assert bp.Parent is None
this_vsbp = VSBreakpoint(
PurePath(bp.File), bp.FileLine, bp.FileColumn, bp.Condition
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def _get_results_path(self, test_name):
"""Returns the path to the test results directory for the test denoted
by test_name.
"""
assert self.context.options.results_directory != None
assert self.context.options.results_directory is not None
return os.path.join(
self.context.options.results_directory,
self._get_results_basename(test_name),
Expand Down
2 changes: 1 addition & 1 deletion cross-project-tests/lit.cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@

def get_required_attr(config, attr_name):
attr_value = getattr(config, attr_name, None)
if attr_value == None:
if attr_value is None:
lit_config.fatal(
"No attribute %r in test configuration! You may need to run "
"tests from your build directory or add this attribute "
Expand Down
2 changes: 1 addition & 1 deletion lldb/bindings/interface/SBBreakpointDocstrings.i
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions lldb/bindings/interface/SBDataExtensions.i
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions lldb/docs/use/python.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion lldb/examples/python/armv7_cortex_m_target_defintion.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion lldb/packages/Python/lldbsuite/test/dotest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Expand Down
6 changes: 3 additions & 3 deletions lldb/packages/Python/lldbsuite/test/lldbtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Expand Down Expand Up @@ -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 = ""
Expand Down Expand Up @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions lldb/packages/Python/lldbsuite/test/lldbutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading
Loading