https://github.com/e-kwsm updated https://github.com/llvm/llvm-project/pull/91857
>From 8379b042ef389e7c032e1bc3b32957bd386e2411 Mon Sep 17 00:00:00 2001 From: Eisuke Kawashima <e-k...@users.noreply.github.com> Date: Sat, 11 May 2024 23:57:11 +0900 Subject: [PATCH 1/2] fix(python): 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. --- .../clang-tidy/checks/gen-static-analyzer-docs.py | 2 +- clang/docs/DebuggingCoroutines.rst | 8 ++++---- clang/tools/include-mapping/gen_std.py | 2 +- clang/utils/check_cfc/obj_diff.py | 2 +- clang/utils/module-deps-to-rsp.py | 2 +- compiler-rt/test/asan/lit.cfg.py | 2 +- compiler-rt/test/builtins/Unit/lit.cfg.py | 2 +- compiler-rt/test/ctx_profile/lit.cfg.py | 2 +- compiler-rt/test/lsan/lit.common.cfg.py | 2 +- compiler-rt/test/memprof/lit.cfg.py | 2 +- compiler-rt/test/profile/lit.cfg.py | 2 +- .../android_commands/android_compile.py | 2 +- .../sanitizer_common/ios_commands/iossim_compile.py | 2 +- compiler-rt/test/ubsan/lit.common.cfg.py | 2 +- compiler-rt/test/ubsan_minimal/lit.common.cfg.py | 2 +- .../dexter/dex/command/ParseCommand.py | 2 +- .../DebuggerControllers/ConditionalController.py | 4 ++-- .../DebuggerControllers/ControllerHelpers.py | 2 +- .../debuginfo-tests/dexter/dex/debugger/Debuggers.py | 2 +- .../dexter/dex/debugger/visualstudio/VisualStudio.py | 2 +- .../debuginfo-tests/dexter/dex/tools/test/Tool.py | 2 +- cross-project-tests/lit.cfg.py | 2 +- lldb/docs/use/python.rst | 4 ++-- .../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 +- .../step_scripted/TestStepScripted.py | 2 +- .../TestStopOnSharedlibraryEvents.py | 2 +- lldb/test/API/lua_api/TestLuaAPI.py | 2 +- .../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 +- .../API/python_api/was_interrupted/interruptible.py | 2 +- lldb/test/Shell/lit.cfg.py | 2 +- llvm/utils/indirect_calls.py | 2 +- llvm/utils/lit/lit/TestRunner.py | 2 +- llvm/utils/lit/lit/util.py | 2 +- llvm/utils/schedcover.py | 2 +- llvm/utils/shuffle_select_fuzz_tester.py | 12 ++++++------ mlir/test/python/ir/affine_expr.py | 2 +- mlir/test/python/ir/attributes.py | 8 ++++---- mlir/test/python/ir/builtin_types.py | 8 ++++---- openmp/libompd/gdb-plugin/ompd/ompd_callbacks.py | 2 +- polly/lib/External/isl/libisl-gdb.py | 4 ++-- polly/lib/External/isl/python/isl.py.top | 4 ++-- polly/utils/pyscop/isl.py | 8 ++++---- 50 files changed, 75 insertions(+), 75 deletions(-) diff --git a/clang-tools-extra/docs/clang-tidy/checks/gen-static-analyzer-docs.py b/clang-tools-extra/docs/clang-tidy/checks/gen-static-analyzer-docs.py index 6545a3906fa50..53ecb60dec539 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/gen-static-analyzer-docs.py +++ b/clang-tools-extra/docs/clang-tidy/checks/gen-static-analyzer-docs.py @@ -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 diff --git a/clang/docs/DebuggingCoroutines.rst b/clang/docs/DebuggingCoroutines.rst index 53bdd08fdbc02..7f464c1f4f28c 100644 --- a/clang/docs/DebuggingCoroutines.rst +++ b/clang/docs/DebuggingCoroutines.rst @@ -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) @@ -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: @@ -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 diff --git a/clang/tools/include-mapping/gen_std.py b/clang/tools/include-mapping/gen_std.py index fcd3bd0d843ea..f362227bc6aab 100755 --- a/clang/tools/include-mapping/gen_std.py +++ b/clang/tools/include-mapping/gen_std.py @@ -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> diff --git a/clang/utils/check_cfc/obj_diff.py b/clang/utils/check_cfc/obj_diff.py index 99ed19e522be2..9d602593a4e1a 100755 --- a/clang/utils/check_cfc/obj_diff.py +++ b/clang/utils/check_cfc/obj_diff.py @@ -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 diff --git a/clang/utils/module-deps-to-rsp.py b/clang/utils/module-deps-to-rsp.py index 6c9f263a786ef..b57a44e5c8780 100755 --- a/clang/utils/module-deps-to-rsp.py +++ b/clang/utils/module-deps-to-rsp.py @@ -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"] diff --git a/compiler-rt/test/asan/lit.cfg.py b/compiler-rt/test/asan/lit.cfg.py index 83b3cbe789cac..7491568e55808 100644 --- a/compiler-rt/test/asan/lit.cfg.py +++ b/compiler-rt/test/asan/lit.cfg.py @@ -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 " diff --git a/compiler-rt/test/builtins/Unit/lit.cfg.py b/compiler-rt/test/builtins/Unit/lit.cfg.py index f63d15919888e..c18c973d54c13 100644 --- a/compiler-rt/test/builtins/Unit/lit.cfg.py +++ b/compiler-rt/test/builtins/Unit/lit.cfg.py @@ -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 " diff --git a/compiler-rt/test/ctx_profile/lit.cfg.py b/compiler-rt/test/ctx_profile/lit.cfg.py index 3034fadbb7a61..74d9bfd11ae28 100644 --- a/compiler-rt/test/ctx_profile/lit.cfg.py +++ b/compiler-rt/test/ctx_profile/lit.cfg.py @@ -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 " diff --git a/compiler-rt/test/lsan/lit.common.cfg.py b/compiler-rt/test/lsan/lit.common.cfg.py index e9b974955730d..9426b7d108bbf 100644 --- a/compiler-rt/test/lsan/lit.common.cfg.py +++ b/compiler-rt/test/lsan/lit.common.cfg.py @@ -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 " diff --git a/compiler-rt/test/memprof/lit.cfg.py b/compiler-rt/test/memprof/lit.cfg.py index 4e5d7ba405a20..4057da0c65b51 100644 --- a/compiler-rt/test/memprof/lit.cfg.py +++ b/compiler-rt/test/memprof/lit.cfg.py @@ -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 " diff --git a/compiler-rt/test/profile/lit.cfg.py b/compiler-rt/test/profile/lit.cfg.py index d3ba115731c5d..191947e4f64aa 100644 --- a/compiler-rt/test/profile/lit.cfg.py +++ b/compiler-rt/test/profile/lit.cfg.py @@ -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 " diff --git a/compiler-rt/test/sanitizer_common/android_commands/android_compile.py b/compiler-rt/test/sanitizer_common/android_commands/android_compile.py index f86831ffef899..e9c6738a09a3f 100755 --- a/compiler-rt/test/sanitizer_common/android_commands/android_compile.py +++ b/compiler-rt/test/sanitizer_common/android_commands/android_compile.py @@ -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) diff --git a/compiler-rt/test/sanitizer_common/ios_commands/iossim_compile.py b/compiler-rt/test/sanitizer_common/ios_commands/iossim_compile.py index 39b211b093c92..2eac1a9bab455 100755 --- a/compiler-rt/test/sanitizer_common/ios_commands/iossim_compile.py +++ b/compiler-rt/test/sanitizer_common/ios_commands/iossim_compile.py @@ -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) diff --git a/compiler-rt/test/ubsan/lit.common.cfg.py b/compiler-rt/test/ubsan/lit.common.cfg.py index 61f6818cce064..04d6f24de5a9f 100644 --- a/compiler-rt/test/ubsan/lit.common.cfg.py +++ b/compiler-rt/test/ubsan/lit.common.cfg.py @@ -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 " diff --git a/compiler-rt/test/ubsan_minimal/lit.common.cfg.py b/compiler-rt/test/ubsan_minimal/lit.common.cfg.py index d398d3a0a8162..e60aed6512fb9 100644 --- a/compiler-rt/test/ubsan_minimal/lit.common.cfg.py +++ b/compiler-rt/test/ubsan_minimal/lit.common.cfg.py @@ -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 " diff --git a/cross-project-tests/debuginfo-tests/dexter/dex/command/ParseCommand.py b/cross-project-tests/debuginfo-tests/dexter/dex/command/ParseCommand.py index 29d7867e80867..4b086e14d4050 100644 --- a/cross-project-tests/debuginfo-tests/dexter/dex/command/ParseCommand.py +++ b/cross-project-tests/debuginfo-tests/dexter/dex/command/ParseCommand.py @@ -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) diff --git a/cross-project-tests/debuginfo-tests/dexter/dex/debugger/DebuggerControllers/ConditionalController.py b/cross-project-tests/debuginfo-tests/dexter/dex/debugger/DebuggerControllers/ConditionalController.py index a7d6b570b55e8..ac3054c3a0edf 100644 --- a/cross-project-tests/debuginfo-tests/dexter/dex/debugger/DebuggerControllers/ConditionalController.py +++ b/cross-project-tests/debuginfo-tests/dexter/dex/debugger/DebuggerControllers/ConditionalController.py @@ -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 = [] @@ -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 diff --git a/cross-project-tests/debuginfo-tests/dexter/dex/debugger/DebuggerControllers/ControllerHelpers.py b/cross-project-tests/debuginfo-tests/dexter/dex/debugger/DebuggerControllers/ControllerHelpers.py index 3e5a7b919d703..a4ca5ae0158e9 100644 --- a/cross-project-tests/debuginfo-tests/dexter/dex/debugger/DebuggerControllers/ControllerHelpers.py +++ b/cross-project-tests/debuginfo-tests/dexter/dex/debugger/DebuggerControllers/ControllerHelpers.py @@ -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) diff --git a/cross-project-tests/debuginfo-tests/dexter/dex/debugger/Debuggers.py b/cross-project-tests/debuginfo-tests/dexter/dex/debugger/Debuggers.py index 1b0d4d5871cbe..67b715af78698 100644 --- a/cross-project-tests/debuginfo-tests/dexter/dex/debugger/Debuggers.py +++ b/cross-project-tests/debuginfo-tests/dexter/dex/debugger/Debuggers.py @@ -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}"</>' diff --git a/cross-project-tests/debuginfo-tests/dexter/dex/debugger/visualstudio/VisualStudio.py b/cross-project-tests/debuginfo-tests/dexter/dex/debugger/visualstudio/VisualStudio.py index 0e20cfbbd264b..f87e1312819e2 100644 --- a/cross-project-tests/debuginfo-tests/dexter/dex/debugger/visualstudio/VisualStudio.py +++ b/cross-project-tests/debuginfo-tests/dexter/dex/debugger/visualstudio/VisualStudio.py @@ -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 ) diff --git a/cross-project-tests/debuginfo-tests/dexter/dex/tools/test/Tool.py b/cross-project-tests/debuginfo-tests/dexter/dex/tools/test/Tool.py index f07641041254b..c366062cec7a9 100644 --- a/cross-project-tests/debuginfo-tests/dexter/dex/tools/test/Tool.py +++ b/cross-project-tests/debuginfo-tests/dexter/dex/tools/test/Tool.py @@ -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), diff --git a/cross-project-tests/lit.cfg.py b/cross-project-tests/lit.cfg.py index 774c4eaf4d976..6341d5c300d86 100644 --- a/cross-project-tests/lit.cfg.py +++ b/cross-project-tests/lit.cfg.py @@ -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 " 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 70bc1d85091bc..6a051b9224afd 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: diff --git a/llvm/utils/indirect_calls.py b/llvm/utils/indirect_calls.py index 2bdabc8c4d74f..34d9e8f9422b0 100755 --- a/llvm/utils/indirect_calls.py +++ b/llvm/utils/indirect_calls.py @@ -34,7 +34,7 @@ def look_for_indirect(file): if line.startswith(" ") == False: function = line result = re.search("(call|jmp).*\*", line) - if result != None: + if result is not None: # TODO: Perhaps use cxxfilt to demangle functions? print(function) print(line) diff --git a/llvm/utils/lit/lit/TestRunner.py b/llvm/utils/lit/lit/TestRunner.py index da7fa86fd3917..a6f1a46f09c86 100644 --- a/llvm/utils/lit/lit/TestRunner.py +++ b/llvm/utils/lit/lit/TestRunner.py @@ -197,7 +197,7 @@ def executeShCmd(cmd, shenv, results, timeout=0): timeout """ # Use the helper even when no timeout is required to make - # other code simpler (i.e. avoid bunch of ``!= None`` checks) + # other code simpler (i.e. avoid bunch of ``is not None`` checks) timeoutHelper = TimeoutHelper(timeout) if timeout > 0: timeoutHelper.startTimer() diff --git a/llvm/utils/lit/lit/util.py b/llvm/utils/lit/lit/util.py index 232ddc9171ad3..a2452f5566b77 100644 --- a/llvm/utils/lit/lit/util.py +++ b/llvm/utils/lit/lit/util.py @@ -408,7 +408,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/llvm/utils/schedcover.py b/llvm/utils/schedcover.py index 41d0359462d19..caa73b6d6a747 100755 --- a/llvm/utils/schedcover.py +++ b/llvm/utils/schedcover.py @@ -25,7 +25,7 @@ def add(instr, model, resource=None): def filter_model(m): global filt if m and filt: - return filt.search(m) != None + return filt.search(m) is not None else: return True diff --git a/llvm/utils/shuffle_select_fuzz_tester.py b/llvm/utils/shuffle_select_fuzz_tester.py index 73bac3c18db14..f51945b530d3f 100755 --- a/llvm/utils/shuffle_select_fuzz_tester.py +++ b/llvm/utils/shuffle_select_fuzz_tester.py @@ -157,7 +157,7 @@ def dump(self): ) def calc_value(self): - if self.value != None: + if self.value is not None: print("Trying to calculate the value of a shuffle instruction twice") exit(1) @@ -199,7 +199,7 @@ def dump(self): ) def calc_value(self): - if self.value != None: + if self.value is not None: print("Trying to calculate the value of a select instruction twice") exit(1) @@ -237,7 +237,7 @@ def gen_inputs(ty, num): # In case one of the dimensions (scalar type/number of elements) is provided, # fill the blank dimension and return appropriate Type object. def get_random_type(ty, num_elts): - if ty != None: + if ty is not None: if ty == "i8": is_float = False width = 8 @@ -260,10 +260,10 @@ def get_random_type(ty, num_elts): int_elt_widths = [8, 16, 32, 64] float_elt_widths = [32, 64] - if num_elts == None: + if num_elts is None: num_elts = random.choice(range(2, 65)) - if ty == None: + if ty is None: # 1 for integer type, 0 for floating-point if random.randint(0, 1): is_float = False @@ -388,7 +388,7 @@ def main(): ), "Minimum value greater than maximum." assert args.type in [None, "i8", "i16", "i32", "i64", "f32", "f64"], "Illegal type." assert ( - args.num_elts == None or args.num_elts > 0 + args.num_elts is None or args.num_elts > 0 ), "num_elts must be a positive integer." random.seed(args.seed) diff --git a/mlir/test/python/ir/affine_expr.py b/mlir/test/python/ir/affine_expr.py index 63564303e8315..c7861c1acfe12 100644 --- a/mlir/test/python/ir/affine_expr.py +++ b/mlir/test/python/ir/affine_expr.py @@ -42,7 +42,7 @@ def testAffineExprEq(): # CHECK: False print(a1 == a3) # CHECK: False - print(a1 == None) + print(a1 is None) # CHECK: False print(a1 == "foo") diff --git a/mlir/test/python/ir/attributes.py b/mlir/test/python/ir/attributes.py index dbd6bad05e01d..0f2c8e7b7252a 100644 --- a/mlir/test/python/ir/attributes.py +++ b/mlir/test/python/ir/attributes.py @@ -56,8 +56,8 @@ def testAttrEq(): print("a1 == a2:", a1 == a2) # CHECK: a1 == a3: True print("a1 == a3:", a1 == a3) - # CHECK: a1 == None: False - print("a1 == None:", a1 == None) + # CHECK: a1 is None: False + print("a1 is None:", a1 is None) # CHECK-LABEL: TEST: testAttrHash @@ -109,9 +109,9 @@ def testAttrEqDoesNotRaise(): # CHECK: False print(a1 == not_an_attr) # CHECK: False - print(a1 == None) + print(a1 is None) # CHECK: True - print(a1 != None) + print(a1 is not None) # CHECK-LABEL: TEST: testAttrCapsule diff --git a/mlir/test/python/ir/builtin_types.py b/mlir/test/python/ir/builtin_types.py index 4eea1a9c372ef..cfe377c703717 100644 --- a/mlir/test/python/ir/builtin_types.py +++ b/mlir/test/python/ir/builtin_types.py @@ -57,8 +57,8 @@ def testTypeEq(): print("t1 == t2:", t1 == t2) # CHECK: t1 == t3: True print("t1 == t3:", t1 == t3) - # CHECK: t1 == None: False - print("t1 == None:", t1 == None) + # CHECK: t1 is None: False + print("t1 is None:", t1 is None) # CHECK-LABEL: TEST: testTypeHash @@ -143,9 +143,9 @@ def testTypeEqDoesNotRaise(): # CHECK: False print(t1 == not_a_type) # CHECK: False - print(t1 == None) + print(t1 is None) # CHECK: True - print(t1 != None) + print(t1 is not None) # CHECK-LABEL: TEST: testTypeCapsule diff --git a/openmp/libompd/gdb-plugin/ompd/ompd_callbacks.py b/openmp/libompd/gdb-plugin/ompd/ompd_callbacks.py index ada09d75579f0..40eb3305f2e24 100644 --- a/openmp/libompd/gdb-plugin/ompd/ompd_callbacks.py +++ b/openmp/libompd/gdb-plugin/ompd/ompd_callbacks.py @@ -84,7 +84,7 @@ def _thread_context(*args): m = re.search(r"(0x[a-fA-F0-9]+)", line) elif lwp: m = re.search(r"\([^)]*?(\d+)[^)]*?\)", line) - if m == None: + if m is None: continue pid = int(m.group(1), 0) if pid == thread_id: diff --git a/polly/lib/External/isl/libisl-gdb.py b/polly/lib/External/isl/libisl-gdb.py index bf01bc583d15d..bdd3949cf89c0 100644 --- a/polly/lib/External/isl/libisl-gdb.py +++ b/polly/lib/External/isl/libisl-gdb.py @@ -70,7 +70,7 @@ def invoke(self, arg, from_tty): arg = gdb.parse_and_eval(arg) printer = str_lookup_function(arg) - if printer == None: + if printer is None: print("No isl printer for this type") return @@ -90,7 +90,7 @@ def str_lookup_function(val): lookup_tag = val.type.target() regex = re.compile("^isl_(.*)$") - if lookup_tag == None: + if lookup_tag is None: return None m = regex.match(str(lookup_tag)) diff --git a/polly/lib/External/isl/python/isl.py.top b/polly/lib/External/isl/python/isl.py.top index d041315d4e11d..9dc47a1a83251 100644 --- a/polly/lib/External/isl/python/isl.py.top +++ b/polly/lib/External/isl/python/isl.py.top @@ -3,7 +3,7 @@ from ctypes import * from ctypes.util import find_library isl_dyld_library_path = os.environ.get('ISL_DYLD_LIBRARY_PATH') -if isl_dyld_library_path != None: +if isl_dyld_library_path is not None: os.environ['DYLD_LIBRARY_PATH'] = isl_dyld_library_path try: isl = cdll.LoadLibrary(isl_dlname) @@ -29,7 +29,7 @@ class Context: @staticmethod def getDefaultInstance(): - if Context.defaultInstance == None: + if Context.defaultInstance is None: Context.defaultInstance = Context() return Context.defaultInstance diff --git a/polly/utils/pyscop/isl.py b/polly/utils/pyscop/isl.py index 5eaf7798e20b9..c06b7bca28042 100644 --- a/polly/utils/pyscop/isl.py +++ b/polly/utils/pyscop/isl.py @@ -24,7 +24,7 @@ def from_ptr(ptr): @staticmethod def getDefaultInstance(): - if Context.defaultInstance == None: + if Context.defaultInstance is None: Context.defaultInstance = Context() return Context.defaultInstance @@ -33,12 +33,12 @@ def getDefaultInstance(): class IslObject: def __init__(self, string="", ctx=None, ptr=None): self.initialize_isl_methods() - if ptr != None: + if ptr is not None: self.ptr = ptr self.ctx = self.get_isl_method("get_ctx")(self) return - if ctx == None: + if ctx is None: ctx = Context.getDefaultInstance() self.ctx = ctx @@ -236,7 +236,7 @@ class Printer: FORMAT_EXT_POLYLIB = 6 def __init__(self, ctx=None): - if ctx == None: + if ctx is None: ctx = Context.getDefaultInstance() self.ctx = ctx >From c21913828d91e318798eb23ff44020c30cf8cd7f Mon Sep 17 00:00:00 2001 From: Eisuke Kawashima <e-k...@users.noreply.github.com> Date: Sat, 11 May 2024 23:57:11 +0900 Subject: [PATCH 2/2] fixup! fix(python): 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. --- bolt/docs/generate_doc.py | 4 ++-- bolt/test/perf2bolt/lit.local.cfg | 2 +- .../clang-tidy/readability/IdentifierNamingCheck.cpp | 2 +- lldb/bindings/interface/SBBreakpointDocstrings.i | 2 +- lldb/bindings/interface/SBDataExtensions.i | 8 ++++---- polly/lib/External/isl/interface/python.cc | 2 +- polly/test/lit.site.cfg.in | 2 +- utils/bazel/configure.bzl | 4 ++-- 8 files changed, 13 insertions(+), 13 deletions(-) diff --git a/bolt/docs/generate_doc.py b/bolt/docs/generate_doc.py index d8829daf677b4..763dc00b44ca3 100644 --- a/bolt/docs/generate_doc.py +++ b/bolt/docs/generate_doc.py @@ -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, [] @@ -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 diff --git a/bolt/test/perf2bolt/lit.local.cfg b/bolt/test/perf2bolt/lit.local.cfg index 05f41ff333b0e..4ee9ad08cc78a 100644 --- a/bolt/test/perf2bolt/lit.local.cfg +++ b/bolt/test/perf2bolt/lit.local.cfg @@ -1,4 +1,4 @@ import shutil -if shutil.which("perf") != None: +if shutil.which("perf") is not None: config.available_features.add("perf") \ No newline at end of file diff --git a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp index 828f13805a698..1b1857124eb0f 100644 --- a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp @@ -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) 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/polly/lib/External/isl/interface/python.cc b/polly/lib/External/isl/interface/python.cc index e4a8288631297..b60bf315ca703 100644 --- a/polly/lib/External/isl/interface/python.cc +++ b/polly/lib/External/isl/interface/python.cc @@ -347,7 +347,7 @@ static void print_persistent_callback_failure_check(int indent, printf(fmt, 0); printf(", '%s') and ", callback_name.c_str()); printf(fmt, 0); - printf(".%s['exc_info'] != None:\n", callback_name.c_str()); + printf(".%s['exc_info'] is not None:\n", callback_name.c_str()); print_indent(indent, " exc_info = "); printf(fmt, 0); printf(".%s['exc_info'][0]\n", callback_name.c_str()); diff --git a/polly/test/lit.site.cfg.in b/polly/test/lit.site.cfg.in index d8a0b6ae3a3b2..f22063e796def 100644 --- a/polly/test/lit.site.cfg.in +++ b/polly/test/lit.site.cfg.in @@ -14,7 +14,7 @@ config.extra_paths = "@POLLY_TEST_EXTRA_PATHS@".split(";") ## Check the current platform with regex import re EAT_ERR_ON_X86 = ' ' -if (re.match(r'^x86_64*', '@LLVM_TARGET_TRIPLE@') == None) : +if (re.match(r'^x86_64*', '@LLVM_TARGET_TRIPLE@') is None) : EAT_ERR_ON_X86 = '|| echo \"error is eaten\"' for arch in config.targets_to_build.split(): diff --git a/utils/bazel/configure.bzl b/utils/bazel/configure.bzl index 717b86d7d6e8a..9c3bb321a5afa 100644 --- a/utils/bazel/configure.bzl +++ b/utils/bazel/configure.bzl @@ -110,7 +110,7 @@ def _extract_cmake_settings(repository_ctx, llvm_cmake): # Skip if `CMAKE_CXX_STANDARD` is set with # `LLVM_REQUIRED_CXX_STANDARD`. # Then `v` will not be desired form, like "${...} CACHE" - if c[k] != None: + if c[k] is not None: continue # Pick up 1st word as the value. @@ -160,7 +160,7 @@ def _llvm_configure_impl(repository_ctx): repository_ctx, "cmake/Modules/LLVMVersion.cmake", ) - version = {k: v for k, v in version.items() if v != None} + version = {k: v for k, v in version.items() if v is not None} vars.update(version) _write_dict_to_file( _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits