-
Notifications
You must be signed in to change notification settings - Fork 13.5k
fix(python): fix invalid escape sequences #91856
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
Conversation
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write If you have received no comments on your PR for a week, you can request a review If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
@llvm/pr-subscribers-lldb @llvm/pr-subscribers-clang Author: Eisuke Kawashima (e-kwsm) ChangesPatch is 120.87 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/91856.diff 100 Files Affected:
diff --git a/.github/workflows/version-check.py b/.github/workflows/version-check.py
index f75fd50300881..ed41ef4e1b16b 100755
--- a/.github/workflows/version-check.py
+++ b/.github/workflows/version-check.py
@@ -6,7 +6,7 @@
def get_version_from_tag(tag):
- m = re.match("llvmorg-([0-9]+)\.([0-9]+)\.([0-9]+)(-rc[0-9]+)?$", tag)
+ m = re.match(r"llvmorg-([0-9]+)\.([0-9]+)\.([0-9]+)(-rc[0-9]+)?$", tag)
if m:
if m.lastindex == 4:
# We have an rc tag.
diff --git a/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py b/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
index d96b3450fdbe8..b048460abf2fc 100755
--- a/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
+++ b/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
@@ -242,7 +242,7 @@ def main():
filename = None
lines_by_file = {}
for line in sys.stdin:
- match = re.search('^\+\+\+\ "?(.*?/){%s}([^ \t\n"]*)' % args.p, line)
+ match = re.search('^\\+\\+\\+\\ "?(.*?/){%s}([^ \t\n"]*)' % args.p, line)
if match:
filename = match.group(2)
if filename is None:
@@ -255,7 +255,7 @@ def main():
if not re.match("^%s$" % args.iregex, filename, re.IGNORECASE):
continue
- match = re.search("^@@.*\+(\d+)(,(\d+))?", line)
+ match = re.search(r"^@@.*\+(\d+)(,(\d+))?", line)
if match:
start_line = int(match.group(1))
line_count = 1
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..c19a0d3de7f11 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
@@ -59,7 +59,7 @@ def get_checkers(checkers_td, checkers_rst):
"clang-analyzer-" + checker_package_prefix + "." + checker_name
)
anchor_url = re.sub(
- "\.", "-", checker_package_prefix + "." + checker_name
+ r"\.", "-", checker_package_prefix + "." + checker_name
).lower()
if not hidden and "alpha" not in full_package_name.lower():
diff --git a/clang/docs/tools/dump_ast_matchers.py b/clang/docs/tools/dump_ast_matchers.py
index 705ff0d4d4098..d47111819a1e2 100755
--- a/clang/docs/tools/dump_ast_matchers.py
+++ b/clang/docs/tools/dump_ast_matchers.py
@@ -86,11 +86,11 @@ def extract_result_types(comment):
parsed.
"""
result_types = []
- m = re.search(r"Usable as: Any Matcher[\s\n]*$", comment, re.S)
+ m = re.search("Usable as: Any Matcher[\\s\n]*$", comment, re.S)
if m:
return ["*"]
while True:
- m = re.match(r"^(.*)Matcher<([^>]+)>\s*,?[\s\n]*$", comment, re.S)
+ m = re.match("^(.*)Matcher<([^>]+)>\\s*,?[\\s\n]*$", comment, re.S)
if not m:
if re.search(r"Usable as:\s*$", comment):
return result_types
@@ -101,9 +101,9 @@ def extract_result_types(comment):
def strip_doxygen(comment):
- """Returns the given comment without \-escaped words."""
+ r"""Returns the given comment without \-escaped words."""
# If there is only a doxygen keyword in the line, delete the whole line.
- comment = re.sub(r"^\\[^\s]+\n", r"", comment, flags=re.M)
+ comment = re.sub("^\\\\[^\\s]+\n", r"", comment, flags=re.M)
# If there is a doxygen \see command, change the \see prefix into "See also:".
# FIXME: it would be better to turn this into a link to the target instead.
@@ -236,7 +236,7 @@ def act_on_decl(declaration, comment, allowed_types):
# Parse the various matcher definition macros.
m = re.match(
- """.*AST_TYPE(LOC)?_TRAVERSE_MATCHER(?:_DECL)?\(
+ r""".*AST_TYPE(LOC)?_TRAVERSE_MATCHER(?:_DECL)?\(
\s*([^\s,]+\s*),
\s*(?:[^\s,]+\s*),
\s*AST_POLYMORPHIC_SUPPORTED_TYPES\(([^)]*)\)
diff --git a/clang/test/Analysis/check-analyzer-fixit.py b/clang/test/Analysis/check-analyzer-fixit.py
index b616255de89b0..43968f4b1b6e8 100644
--- a/clang/test/Analysis/check-analyzer-fixit.py
+++ b/clang/test/Analysis/check-analyzer-fixit.py
@@ -55,7 +55,7 @@ def run_test_once(args, extra_args):
# themselves. We need to keep the comments to preserve line numbers while
# avoiding empty lines which could potentially trigger formatting-related
# checks.
- cleaned_test = re.sub("// *CHECK-[A-Z0-9\-]*:[^\r\n]*", "//", input_text)
+ cleaned_test = re.sub("// *CHECK-[A-Z0-9\\-]*:[^\r\n]*", "//", input_text)
write_file(temp_file_name, cleaned_test)
original_file_name = temp_file_name + ".orig"
diff --git a/compiler-rt/lib/asan/scripts/asan_symbolize.py b/compiler-rt/lib/asan/scripts/asan_symbolize.py
index b08769614aeb1..058a1614b55e6 100755
--- a/compiler-rt/lib/asan/scripts/asan_symbolize.py
+++ b/compiler-rt/lib/asan/scripts/asan_symbolize.py
@@ -316,7 +316,7 @@ def symbolize(self, addr, binary, offset):
# * For C functions atos omits parentheses and argument types.
# * For C++ functions the function name (i.e., `foo` above) may contain
# templates which may contain parentheses.
- match = re.match("^(.*) \(in (.*)\) \((.*:\d*)\)$", atos_line)
+ match = re.match(r"^(.*) \(in (.*)\) \((.*:\d*)\)$", atos_line)
logging.debug("atos_line: %s", atos_line)
if match:
function_name = match.group(1)
@@ -541,7 +541,7 @@ def process_line_posix(self, line):
# names in the regex because it could be an
# Objective-C or C++ demangled name.
stack_trace_line_format = (
- "^( *#([0-9]+) *)(0x[0-9a-f]+) *(?:in *.+)? *\((.*)\+(0x[0-9a-f]+)\)"
+ r"^( *#([0-9]+) *)(0x[0-9a-f]+) *(?:in *.+)? *\((.*)\+(0x[0-9a-f]+)\)"
)
match = re.match(stack_trace_line_format, line)
if not match:
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..fa6647a0fd56d 100644
--- a/cross-project-tests/debuginfo-tests/dexter/dex/command/ParseCommand.py
+++ b/cross-project-tests/debuginfo-tests/dexter/dex/command/ParseCommand.py
@@ -128,7 +128,7 @@ def get_address_object(address_name: str, offset: int = 0):
def _search_line_for_cmd_start(line: str, start: int, valid_commands: dict) -> int:
- """Scan `line` for a string matching any key in `valid_commands`.
+ r"""Scan `line` for a string matching any key in `valid_commands`.
Start searching from `start`.
Commands escaped with `\` (E.g. `\DexLabel('a')`) are ignored.
@@ -543,7 +543,7 @@ def test_parse_share_line(self):
def test_parse_escaped(self):
"""Escaped commands are ignored."""
- lines = ['words \MockCmd("IGNORED") words words words\n']
+ lines = ['words \\MockCmd("IGNORED") words words words\n']
values = self._find_all_mock_values_in_lines(lines)
diff --git a/cross-project-tests/lit.cfg.py b/cross-project-tests/lit.cfg.py
index 774c4eaf4d976..c7d3217c99304 100644
--- a/cross-project-tests/lit.cfg.py
+++ b/cross-project-tests/lit.cfg.py
@@ -226,7 +226,7 @@ def can_target_host():
xcode_lldb_vers = subprocess.check_output(["xcrun", "lldb", "--version"]).decode(
"utf-8"
)
- match = re.search("lldb-(\d+)", xcode_lldb_vers)
+ match = re.search(r"lldb-(\d+)", xcode_lldb_vers)
if match:
apple_lldb_vers = int(match.group(1))
if apple_lldb_vers < 1000:
@@ -250,7 +250,7 @@ def get_gdb_version_string():
if len(gdb_vers_lines) < 1:
print("Unkown GDB version format (too few lines)", file=sys.stderr)
return None
- match = re.search("GNU gdb \(.*?\) ((\d|\.)+)", gdb_vers_lines[0].strip())
+ match = re.search(r"GNU gdb \(.*?\) ((\d|\.)+)", gdb_vers_lines[0].strip())
if match is None:
print(f"Unkown GDB version format: {gdb_vers_lines[0]}", file=sys.stderr)
return None
@@ -264,7 +264,7 @@ def get_clang_default_dwarf_version_string(triple):
# Get the flags passed by the driver and look for -dwarf-version.
cmd = f'{llvm_config.use_llvm_tool("clang")} -g -xc -c - -v -### --target={triple}'
stderr = subprocess.run(cmd.split(), stderr=subprocess.PIPE).stderr.decode()
- match = re.search("-dwarf-version=(\d+)", stderr)
+ match = re.search(r"-dwarf-version=(\d+)", stderr)
if match is None:
print("Cannot determine default dwarf version", file=sys.stderr)
return None
diff --git a/libcxx/test/libcxx/transitive_includes.gen.py b/libcxx/test/libcxx/transitive_includes.gen.py
index a67cab693b6e2..b5e91fb8ceb50 100644
--- a/libcxx/test/libcxx/transitive_includes.gen.py
+++ b/libcxx/test/libcxx/transitive_includes.gen.py
@@ -59,7 +59,7 @@
continue
# Escape slashes for the awk command below
- escaped_header = header.replace('/', '\/')
+ escaped_header = header.replace('/', r'\/')
print(f"""\
//--- {header}.sh.cpp
diff --git a/libcxx/utils/generate_escaped_output_table.py b/libcxx/utils/generate_escaped_output_table.py
index 523a0be3a451d..9e7ea814ee221 100755
--- a/libcxx/utils/generate_escaped_output_table.py
+++ b/libcxx/utils/generate_escaped_output_table.py
@@ -84,7 +84,7 @@ def compactPropertyRanges(input: list[PropertyRange]) -> list[PropertyRange]:
return result
-DATA_ARRAY_TEMPLATE = """
+DATA_ARRAY_TEMPLATE = r"""
/// The entries of the characters to escape in format's debug string.
///
/// Contains the entries for [format.string.escaped]/2.2.1.2.1
diff --git a/libcxx/utils/generate_width_estimation_table.py b/libcxx/utils/generate_width_estimation_table.py
index 918dae25fe49e..b23b7378ac0c0 100644
--- a/libcxx/utils/generate_width_estimation_table.py
+++ b/libcxx/utils/generate_width_estimation_table.py
@@ -99,7 +99,7 @@ def compactPropertyRanges(input: list[PropertyRange]) -> list[PropertyRange]:
return result
-DATA_ARRAY_TEMPLATE = """
+DATA_ARRAY_TEMPLATE = r"""
/// The entries of the characters with an estimated width of 2.
///
/// Contains the entries for [format.string.std]/12
diff --git a/lld/test/MachO/tools/validate-unwind-info.py b/lld/test/MachO/tools/validate-unwind-info.py
index ac49f1ecb5889..1cc82f8279273 100755
--- a/lld/test/MachO/tools/validate-unwind-info.py
+++ b/lld/test/MachO/tools/validate-unwind-info.py
@@ -11,7 +11,7 @@
def main():
- hex = "[a-f\d]"
+ hex = r"[a-f\d]"
hex8 = hex + "{8}"
parser = argparse.ArgumentParser(description=__doc__)
diff --git a/lld/utils/benchmark.py b/lld/utils/benchmark.py
index a07d5ecc69417..7202e07ec438d 100755
--- a/lld/utils/benchmark.py
+++ b/lld/utils/benchmark.py
@@ -51,7 +51,7 @@ def __str__(self):
def getBenchmarks():
ret = []
for i in glob.glob("*/response*.txt"):
- m = re.match("response-(.*)\.txt", os.path.basename(i))
+ m = re.match(r"response-(.*)\.txt", os.path.basename(i))
variant = m.groups()[0] if m else None
ret.append(Bench(os.path.dirname(i), variant))
return ret
diff --git a/lldb/examples/python/crashlog.py b/lldb/examples/python/crashlog.py
index 641b2e64d53b1..13e5d77ec6fe2 100755
--- a/lldb/examples/python/crashlog.py
+++ b/lldb/examples/python/crashlog.py
@@ -294,7 +294,7 @@ class DarwinImage(symbolication.Image):
except:
dsymForUUIDBinary = ""
- dwarfdump_uuid_regex = re.compile("UUID: ([-0-9a-fA-F]+) \(([^\(]+)\) .*")
+ dwarfdump_uuid_regex = re.compile(r"UUID: ([-0-9a-fA-F]+) \(([^\(]+)\) .*")
def __init__(
self, text_addr_lo, text_addr_hi, identifier, version, uuid, path, verbose
@@ -499,7 +499,7 @@ def find_image_with_identifier(self, identifier):
for image in self.images:
if image.identifier == identifier:
return image
- regex_text = "^.*\.%s$" % (re.escape(identifier))
+ regex_text = r"^.*\.%s$" % (re.escape(identifier))
regex = re.compile(regex_text)
for image in self.images:
if regex.match(image.identifier):
@@ -919,7 +919,7 @@ def get(cls):
version = r"(?:" + super().version + r"\s+)?"
address = r"(0x[0-9a-fA-F]{4,})" # 4 digits or more
- symbol = """
+ symbol = r"""
(?:
[ ]+
(?P<symbol>.+)
@@ -1089,7 +1089,7 @@ def parse_normal(self, line):
self.crashlog.process_identifier = line[11:].strip()
elif line.startswith("Version:"):
version_string = line[8:].strip()
- matched_pair = re.search("(.+)\((.+)\)", version_string)
+ matched_pair = re.search(r"(.+)\((.+)\)", version_string)
if matched_pair:
self.crashlog.process_version = matched_pair.group(1)
self.crashlog.process_compatability_version = matched_pair.group(2)
diff --git a/lldb/examples/python/delta.py b/lldb/examples/python/delta.py
index eeb3c177cfa90..f847b95ab119f 100755
--- a/lldb/examples/python/delta.py
+++ b/lldb/examples/python/delta.py
@@ -99,7 +99,7 @@ def parse_log_file(file, options):
print("# Log file: '%s'" % file)
print("#----------------------------------------------------------------------")
- timestamp_regex = re.compile("(\s*)([1-9][0-9]+\.[0-9]+)([^0-9].*)$")
+ timestamp_regex = re.compile(r"(\s*)([1-9][0-9]+\.[0-9]+)([^0-9].*)$")
base_time = 0.0
last_time = 0.0
diff --git a/lldb/examples/python/gdbremote.py b/lldb/examples/python/gdbremote.py
index 40ee15853fdb2..0bbfc1a0f1eed 100755
--- a/lldb/examples/python/gdbremote.py
+++ b/lldb/examples/python/gdbremote.py
@@ -1537,12 +1537,12 @@ def parse_gdb_log(file, options):
a long time during a preset set of debugger commands."""
tricky_commands = ["qRegisterInfo"]
- timestamp_regex = re.compile("(\s*)([1-9][0-9]+\.[0-9]+)([^0-9].*)$")
+ timestamp_regex = re.compile(r"(\s*)([1-9][0-9]+\.[0-9]+)([^0-9].*)$")
packet_name_regex = re.compile("([A-Za-z_]+)[^a-z]")
packet_transmit_name_regex = re.compile(
"(?P<direction>send|read) packet: (?P<packet>.*)"
)
- packet_contents_name_regex = re.compile("\$([^#]*)#[0-9a-fA-F]{2}")
+ packet_contents_name_regex = re.compile(r"\$([^#]*)#[0-9a-fA-F]{2}")
packet_checksum_regex = re.compile(".*#[0-9a-fA-F]{2}$")
packet_names_regex_str = "(" + "|".join(gdb_remote_commands.keys()) + ")(.*)"
packet_names_regex = re.compile(packet_names_regex_str)
diff --git a/lldb/examples/python/jump.py b/lldb/examples/python/jump.py
index e086df5fd1528..8d52bd9af43f6 100644
--- a/lldb/examples/python/jump.py
+++ b/lldb/examples/python/jump.py
@@ -38,7 +38,7 @@ def parse_linespec(linespec, frame, result):
)
if not matched:
- mo = re.match("^\+([0-9]+)$", linespec)
+ mo = re.match(r"^\+([0-9]+)$", linespec)
if mo is not None:
matched = True
# print "Matched +<count>"
@@ -54,7 +54,7 @@ def parse_linespec(linespec, frame, result):
)
if not matched:
- mo = re.match("^\-([0-9]+)$", linespec)
+ mo = re.match(r"^\-([0-9]+)$", linespec)
if mo is not None:
matched = True
# print "Matched -<count>"
@@ -79,7 +79,7 @@ def parse_linespec(linespec, frame, result):
breakpoint = target.BreakpointCreateByLocation(file_name, line_number)
if not matched:
- mo = re.match("\*((0x)?([0-9a-f]+))$", linespec)
+ mo = re.match(r"\*((0x)?([0-9a-f]+))$", linespec)
if mo is not None:
matched = True
# print "Matched <address-expression>"
diff --git a/lldb/examples/python/performance.py b/lldb/examples/python/performance.py
index 869a0b061cf85..b86b5a52522e0 100755
--- a/lldb/examples/python/performance.py
+++ b/lldb/examples/python/performance.py
@@ -346,7 +346,7 @@ def __init__(self, pid):
def Measure(self):
output = subprocess.getoutput(self.command).split("\n")[-1]
- values = re.split("[-+\s]+", output)
+ values = re.split(r"[-+\s]+", output)
for idx, stat in enumerate(values):
multiplier = 1
if stat:
diff --git a/lldb/examples/python/symbolication.py b/lldb/examples/python/symbolication.py
index f6dcc8b9a7943..b16745ee963c9 100755
--- a/lldb/examples/python/symbolication.py
+++ b/lldb/examples/python/symbolication.py
@@ -177,9 +177,9 @@ class Section:
"""Class that represents an load address range"""
sect_info_regex = re.compile("(?P<name>[^=]+)=(?P<range>.*)")
- addr_regex = re.compile("^\s*(?P<start>0x[0-9A-Fa-f]+)\s*$")
+ addr_regex = re.compile(r"^\s*(?P<start>0x[0-9A-Fa-f]+)\s*$")
range_regex = re.compile(
- "^\s*(?P<start>0x[0-9A-Fa-f]+)\s*(?P<op>[-+])\s*(?P<end>0x[0-9A-Fa-f]+)\s*$"
+ r"^\s*(?P<start>0x[0-9A-Fa-f]+)\s*(?P<op>[-+])\s*(?P<end>0x[0-9A-Fa-f]+)\s*$"
)
def __init__(self, start_addr=None, end_addr=None, name=None):
@@ -557,7 +557,7 @@ def find_images_with_identifier(self, identifier):
if image.identifier == identifier:
images.append(image)
if len(images) == 0:
- regex_text = "^.*\.%s$" % (re.escape(identifier))
+ regex_text = r"^.*\.%s$" % (re.escape(identifier))
regex = re.compile(regex_text)
for image in self.images:
if regex.match(image.identifier):
diff --git a/lldb/packages/Python/lldbsuite/test/lldbpexpect.py b/lldb/packages/Python/lldbsuite/test/lldbpexpect.py
index 998a080565b6b..3279e1fd39f8c 100644
--- a/lldb/packages/Python/lldbsuite/test/lldbpexpect.py
+++ b/lldb/packages/Python/lldbsuite/test/lldbpexpect.py
@@ -104,4 +104,4 @@ def cursor_forward_escape_seq(self, chars_to_move):
Returns the escape sequence to move the cursor forward/right
by a certain amount of characters.
"""
- return b"\x1b\[" + str(chars_to_move).encode("utf-8") + b"C"
+ return b"\x1b\\[" + str(chars_to_move).encode("utf-8") + b"C"
diff --git a/lldb/packages/Python/lldbsuite/test/test_runner/process_control.py b/lldb/packages/Python/lldbsuite/test/test_runner/process_control.py
index 07c17993bc878..8ab219a92d99d 100644
--- a/lldb/packages/Python/lldbsuite/test/test_runner/process_control.py
+++ b/lldb/packages/Python/lldbsuite/test/test_runner/process_control.py
@@ -91,7 +91,7 @@ def timeout_to_seconds(timeout):
class ProcessHelper(object):
- """Provides an interface for accessing process-related functionality.
+ r"""Provides an interface for accessing process-related functionality.
This class provides a factory method that gives the caller a
platform-specific implementation instance of the class.
diff --git a/lldb/test/API/commands/command/backticks/TestBackticksInAlias.py b/lldb/test/API/commands/command/backticks/TestBackticksInAlias.py
index c31a08ac00182..2cb8d225d6d07 100644
--- a/lldb/test/API/commands/command/backticks/TestBackticksInAlias.py
+++ b/lldb/test/API/commands/command/backticks/TestBackticksInAlias.py
@@ -20,7 +20,7 @@ def test_backticks_in_alias(self):
interp = self.dbg.GetCommandInterpreter()
result = lldb.SBCommandReturnObject()
interp.HandleCommand(
- "command alias _test-argv-cmd expression -Z \`argc\` -- argv", result
+ r"command alias _test-argv-cmd expression -Z \`argc\` -- argv", result
)
self.assertCommandReturn(result, "Made the alias")
interp.HandleCommand("_test-argv-cmd", result)
@@ -28,7 +28,7 @@ def test_backticks_in_alias(self):
# Now try a harder case where we create this using an alias:
interp.HandleCommand(
- "command alias _test-argv-parray-cmd parray \`argc\` argv", result
+ r"command alias _test-argv-parray-cmd parray \`argc\` argv", result
)
self.assertCommandReturn(result, "Made the alias")
interp.HandleCommand("_test-argv-parray-cmd", result)
diff --git a/lldb/test/API/commands/expression/memory-allocation/TestMemoryAllocSettings.py b/lldb/test/API/commands/expression/memory-allocation/TestMemoryAllocSettings.py
index d27f07717affb..a82141a0792f2 100644
--- a/lldb/test/API/commands/expression/...
[truncated]
|
@llvm/pr-subscribers-clang-tools-extra Author: Eisuke Kawashima (e-kwsm) ChangesPatch is 120.87 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/91856.diff 100 Files Affected:
diff --git a/.github/workflows/version-check.py b/.github/workflows/version-check.py
index f75fd50300881..ed41ef4e1b16b 100755
--- a/.github/workflows/version-check.py
+++ b/.github/workflows/version-check.py
@@ -6,7 +6,7 @@
def get_version_from_tag(tag):
- m = re.match("llvmorg-([0-9]+)\.([0-9]+)\.([0-9]+)(-rc[0-9]+)?$", tag)
+ m = re.match(r"llvmorg-([0-9]+)\.([0-9]+)\.([0-9]+)(-rc[0-9]+)?$", tag)
if m:
if m.lastindex == 4:
# We have an rc tag.
diff --git a/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py b/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
index d96b3450fdbe8..b048460abf2fc 100755
--- a/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
+++ b/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
@@ -242,7 +242,7 @@ def main():
filename = None
lines_by_file = {}
for line in sys.stdin:
- match = re.search('^\+\+\+\ "?(.*?/){%s}([^ \t\n"]*)' % args.p, line)
+ match = re.search('^\\+\\+\\+\\ "?(.*?/){%s}([^ \t\n"]*)' % args.p, line)
if match:
filename = match.group(2)
if filename is None:
@@ -255,7 +255,7 @@ def main():
if not re.match("^%s$" % args.iregex, filename, re.IGNORECASE):
continue
- match = re.search("^@@.*\+(\d+)(,(\d+))?", line)
+ match = re.search(r"^@@.*\+(\d+)(,(\d+))?", line)
if match:
start_line = int(match.group(1))
line_count = 1
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..c19a0d3de7f11 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
@@ -59,7 +59,7 @@ def get_checkers(checkers_td, checkers_rst):
"clang-analyzer-" + checker_package_prefix + "." + checker_name
)
anchor_url = re.sub(
- "\.", "-", checker_package_prefix + "." + checker_name
+ r"\.", "-", checker_package_prefix + "." + checker_name
).lower()
if not hidden and "alpha" not in full_package_name.lower():
diff --git a/clang/docs/tools/dump_ast_matchers.py b/clang/docs/tools/dump_ast_matchers.py
index 705ff0d4d4098..d47111819a1e2 100755
--- a/clang/docs/tools/dump_ast_matchers.py
+++ b/clang/docs/tools/dump_ast_matchers.py
@@ -86,11 +86,11 @@ def extract_result_types(comment):
parsed.
"""
result_types = []
- m = re.search(r"Usable as: Any Matcher[\s\n]*$", comment, re.S)
+ m = re.search("Usable as: Any Matcher[\\s\n]*$", comment, re.S)
if m:
return ["*"]
while True:
- m = re.match(r"^(.*)Matcher<([^>]+)>\s*,?[\s\n]*$", comment, re.S)
+ m = re.match("^(.*)Matcher<([^>]+)>\\s*,?[\\s\n]*$", comment, re.S)
if not m:
if re.search(r"Usable as:\s*$", comment):
return result_types
@@ -101,9 +101,9 @@ def extract_result_types(comment):
def strip_doxygen(comment):
- """Returns the given comment without \-escaped words."""
+ r"""Returns the given comment without \-escaped words."""
# If there is only a doxygen keyword in the line, delete the whole line.
- comment = re.sub(r"^\\[^\s]+\n", r"", comment, flags=re.M)
+ comment = re.sub("^\\\\[^\\s]+\n", r"", comment, flags=re.M)
# If there is a doxygen \see command, change the \see prefix into "See also:".
# FIXME: it would be better to turn this into a link to the target instead.
@@ -236,7 +236,7 @@ def act_on_decl(declaration, comment, allowed_types):
# Parse the various matcher definition macros.
m = re.match(
- """.*AST_TYPE(LOC)?_TRAVERSE_MATCHER(?:_DECL)?\(
+ r""".*AST_TYPE(LOC)?_TRAVERSE_MATCHER(?:_DECL)?\(
\s*([^\s,]+\s*),
\s*(?:[^\s,]+\s*),
\s*AST_POLYMORPHIC_SUPPORTED_TYPES\(([^)]*)\)
diff --git a/clang/test/Analysis/check-analyzer-fixit.py b/clang/test/Analysis/check-analyzer-fixit.py
index b616255de89b0..43968f4b1b6e8 100644
--- a/clang/test/Analysis/check-analyzer-fixit.py
+++ b/clang/test/Analysis/check-analyzer-fixit.py
@@ -55,7 +55,7 @@ def run_test_once(args, extra_args):
# themselves. We need to keep the comments to preserve line numbers while
# avoiding empty lines which could potentially trigger formatting-related
# checks.
- cleaned_test = re.sub("// *CHECK-[A-Z0-9\-]*:[^\r\n]*", "//", input_text)
+ cleaned_test = re.sub("// *CHECK-[A-Z0-9\\-]*:[^\r\n]*", "//", input_text)
write_file(temp_file_name, cleaned_test)
original_file_name = temp_file_name + ".orig"
diff --git a/compiler-rt/lib/asan/scripts/asan_symbolize.py b/compiler-rt/lib/asan/scripts/asan_symbolize.py
index b08769614aeb1..058a1614b55e6 100755
--- a/compiler-rt/lib/asan/scripts/asan_symbolize.py
+++ b/compiler-rt/lib/asan/scripts/asan_symbolize.py
@@ -316,7 +316,7 @@ def symbolize(self, addr, binary, offset):
# * For C functions atos omits parentheses and argument types.
# * For C++ functions the function name (i.e., `foo` above) may contain
# templates which may contain parentheses.
- match = re.match("^(.*) \(in (.*)\) \((.*:\d*)\)$", atos_line)
+ match = re.match(r"^(.*) \(in (.*)\) \((.*:\d*)\)$", atos_line)
logging.debug("atos_line: %s", atos_line)
if match:
function_name = match.group(1)
@@ -541,7 +541,7 @@ def process_line_posix(self, line):
# names in the regex because it could be an
# Objective-C or C++ demangled name.
stack_trace_line_format = (
- "^( *#([0-9]+) *)(0x[0-9a-f]+) *(?:in *.+)? *\((.*)\+(0x[0-9a-f]+)\)"
+ r"^( *#([0-9]+) *)(0x[0-9a-f]+) *(?:in *.+)? *\((.*)\+(0x[0-9a-f]+)\)"
)
match = re.match(stack_trace_line_format, line)
if not match:
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..fa6647a0fd56d 100644
--- a/cross-project-tests/debuginfo-tests/dexter/dex/command/ParseCommand.py
+++ b/cross-project-tests/debuginfo-tests/dexter/dex/command/ParseCommand.py
@@ -128,7 +128,7 @@ def get_address_object(address_name: str, offset: int = 0):
def _search_line_for_cmd_start(line: str, start: int, valid_commands: dict) -> int:
- """Scan `line` for a string matching any key in `valid_commands`.
+ r"""Scan `line` for a string matching any key in `valid_commands`.
Start searching from `start`.
Commands escaped with `\` (E.g. `\DexLabel('a')`) are ignored.
@@ -543,7 +543,7 @@ def test_parse_share_line(self):
def test_parse_escaped(self):
"""Escaped commands are ignored."""
- lines = ['words \MockCmd("IGNORED") words words words\n']
+ lines = ['words \\MockCmd("IGNORED") words words words\n']
values = self._find_all_mock_values_in_lines(lines)
diff --git a/cross-project-tests/lit.cfg.py b/cross-project-tests/lit.cfg.py
index 774c4eaf4d976..c7d3217c99304 100644
--- a/cross-project-tests/lit.cfg.py
+++ b/cross-project-tests/lit.cfg.py
@@ -226,7 +226,7 @@ def can_target_host():
xcode_lldb_vers = subprocess.check_output(["xcrun", "lldb", "--version"]).decode(
"utf-8"
)
- match = re.search("lldb-(\d+)", xcode_lldb_vers)
+ match = re.search(r"lldb-(\d+)", xcode_lldb_vers)
if match:
apple_lldb_vers = int(match.group(1))
if apple_lldb_vers < 1000:
@@ -250,7 +250,7 @@ def get_gdb_version_string():
if len(gdb_vers_lines) < 1:
print("Unkown GDB version format (too few lines)", file=sys.stderr)
return None
- match = re.search("GNU gdb \(.*?\) ((\d|\.)+)", gdb_vers_lines[0].strip())
+ match = re.search(r"GNU gdb \(.*?\) ((\d|\.)+)", gdb_vers_lines[0].strip())
if match is None:
print(f"Unkown GDB version format: {gdb_vers_lines[0]}", file=sys.stderr)
return None
@@ -264,7 +264,7 @@ def get_clang_default_dwarf_version_string(triple):
# Get the flags passed by the driver and look for -dwarf-version.
cmd = f'{llvm_config.use_llvm_tool("clang")} -g -xc -c - -v -### --target={triple}'
stderr = subprocess.run(cmd.split(), stderr=subprocess.PIPE).stderr.decode()
- match = re.search("-dwarf-version=(\d+)", stderr)
+ match = re.search(r"-dwarf-version=(\d+)", stderr)
if match is None:
print("Cannot determine default dwarf version", file=sys.stderr)
return None
diff --git a/libcxx/test/libcxx/transitive_includes.gen.py b/libcxx/test/libcxx/transitive_includes.gen.py
index a67cab693b6e2..b5e91fb8ceb50 100644
--- a/libcxx/test/libcxx/transitive_includes.gen.py
+++ b/libcxx/test/libcxx/transitive_includes.gen.py
@@ -59,7 +59,7 @@
continue
# Escape slashes for the awk command below
- escaped_header = header.replace('/', '\/')
+ escaped_header = header.replace('/', r'\/')
print(f"""\
//--- {header}.sh.cpp
diff --git a/libcxx/utils/generate_escaped_output_table.py b/libcxx/utils/generate_escaped_output_table.py
index 523a0be3a451d..9e7ea814ee221 100755
--- a/libcxx/utils/generate_escaped_output_table.py
+++ b/libcxx/utils/generate_escaped_output_table.py
@@ -84,7 +84,7 @@ def compactPropertyRanges(input: list[PropertyRange]) -> list[PropertyRange]:
return result
-DATA_ARRAY_TEMPLATE = """
+DATA_ARRAY_TEMPLATE = r"""
/// The entries of the characters to escape in format's debug string.
///
/// Contains the entries for [format.string.escaped]/2.2.1.2.1
diff --git a/libcxx/utils/generate_width_estimation_table.py b/libcxx/utils/generate_width_estimation_table.py
index 918dae25fe49e..b23b7378ac0c0 100644
--- a/libcxx/utils/generate_width_estimation_table.py
+++ b/libcxx/utils/generate_width_estimation_table.py
@@ -99,7 +99,7 @@ def compactPropertyRanges(input: list[PropertyRange]) -> list[PropertyRange]:
return result
-DATA_ARRAY_TEMPLATE = """
+DATA_ARRAY_TEMPLATE = r"""
/// The entries of the characters with an estimated width of 2.
///
/// Contains the entries for [format.string.std]/12
diff --git a/lld/test/MachO/tools/validate-unwind-info.py b/lld/test/MachO/tools/validate-unwind-info.py
index ac49f1ecb5889..1cc82f8279273 100755
--- a/lld/test/MachO/tools/validate-unwind-info.py
+++ b/lld/test/MachO/tools/validate-unwind-info.py
@@ -11,7 +11,7 @@
def main():
- hex = "[a-f\d]"
+ hex = r"[a-f\d]"
hex8 = hex + "{8}"
parser = argparse.ArgumentParser(description=__doc__)
diff --git a/lld/utils/benchmark.py b/lld/utils/benchmark.py
index a07d5ecc69417..7202e07ec438d 100755
--- a/lld/utils/benchmark.py
+++ b/lld/utils/benchmark.py
@@ -51,7 +51,7 @@ def __str__(self):
def getBenchmarks():
ret = []
for i in glob.glob("*/response*.txt"):
- m = re.match("response-(.*)\.txt", os.path.basename(i))
+ m = re.match(r"response-(.*)\.txt", os.path.basename(i))
variant = m.groups()[0] if m else None
ret.append(Bench(os.path.dirname(i), variant))
return ret
diff --git a/lldb/examples/python/crashlog.py b/lldb/examples/python/crashlog.py
index 641b2e64d53b1..13e5d77ec6fe2 100755
--- a/lldb/examples/python/crashlog.py
+++ b/lldb/examples/python/crashlog.py
@@ -294,7 +294,7 @@ class DarwinImage(symbolication.Image):
except:
dsymForUUIDBinary = ""
- dwarfdump_uuid_regex = re.compile("UUID: ([-0-9a-fA-F]+) \(([^\(]+)\) .*")
+ dwarfdump_uuid_regex = re.compile(r"UUID: ([-0-9a-fA-F]+) \(([^\(]+)\) .*")
def __init__(
self, text_addr_lo, text_addr_hi, identifier, version, uuid, path, verbose
@@ -499,7 +499,7 @@ def find_image_with_identifier(self, identifier):
for image in self.images:
if image.identifier == identifier:
return image
- regex_text = "^.*\.%s$" % (re.escape(identifier))
+ regex_text = r"^.*\.%s$" % (re.escape(identifier))
regex = re.compile(regex_text)
for image in self.images:
if regex.match(image.identifier):
@@ -919,7 +919,7 @@ def get(cls):
version = r"(?:" + super().version + r"\s+)?"
address = r"(0x[0-9a-fA-F]{4,})" # 4 digits or more
- symbol = """
+ symbol = r"""
(?:
[ ]+
(?P<symbol>.+)
@@ -1089,7 +1089,7 @@ def parse_normal(self, line):
self.crashlog.process_identifier = line[11:].strip()
elif line.startswith("Version:"):
version_string = line[8:].strip()
- matched_pair = re.search("(.+)\((.+)\)", version_string)
+ matched_pair = re.search(r"(.+)\((.+)\)", version_string)
if matched_pair:
self.crashlog.process_version = matched_pair.group(1)
self.crashlog.process_compatability_version = matched_pair.group(2)
diff --git a/lldb/examples/python/delta.py b/lldb/examples/python/delta.py
index eeb3c177cfa90..f847b95ab119f 100755
--- a/lldb/examples/python/delta.py
+++ b/lldb/examples/python/delta.py
@@ -99,7 +99,7 @@ def parse_log_file(file, options):
print("# Log file: '%s'" % file)
print("#----------------------------------------------------------------------")
- timestamp_regex = re.compile("(\s*)([1-9][0-9]+\.[0-9]+)([^0-9].*)$")
+ timestamp_regex = re.compile(r"(\s*)([1-9][0-9]+\.[0-9]+)([^0-9].*)$")
base_time = 0.0
last_time = 0.0
diff --git a/lldb/examples/python/gdbremote.py b/lldb/examples/python/gdbremote.py
index 40ee15853fdb2..0bbfc1a0f1eed 100755
--- a/lldb/examples/python/gdbremote.py
+++ b/lldb/examples/python/gdbremote.py
@@ -1537,12 +1537,12 @@ def parse_gdb_log(file, options):
a long time during a preset set of debugger commands."""
tricky_commands = ["qRegisterInfo"]
- timestamp_regex = re.compile("(\s*)([1-9][0-9]+\.[0-9]+)([^0-9].*)$")
+ timestamp_regex = re.compile(r"(\s*)([1-9][0-9]+\.[0-9]+)([^0-9].*)$")
packet_name_regex = re.compile("([A-Za-z_]+)[^a-z]")
packet_transmit_name_regex = re.compile(
"(?P<direction>send|read) packet: (?P<packet>.*)"
)
- packet_contents_name_regex = re.compile("\$([^#]*)#[0-9a-fA-F]{2}")
+ packet_contents_name_regex = re.compile(r"\$([^#]*)#[0-9a-fA-F]{2}")
packet_checksum_regex = re.compile(".*#[0-9a-fA-F]{2}$")
packet_names_regex_str = "(" + "|".join(gdb_remote_commands.keys()) + ")(.*)"
packet_names_regex = re.compile(packet_names_regex_str)
diff --git a/lldb/examples/python/jump.py b/lldb/examples/python/jump.py
index e086df5fd1528..8d52bd9af43f6 100644
--- a/lldb/examples/python/jump.py
+++ b/lldb/examples/python/jump.py
@@ -38,7 +38,7 @@ def parse_linespec(linespec, frame, result):
)
if not matched:
- mo = re.match("^\+([0-9]+)$", linespec)
+ mo = re.match(r"^\+([0-9]+)$", linespec)
if mo is not None:
matched = True
# print "Matched +<count>"
@@ -54,7 +54,7 @@ def parse_linespec(linespec, frame, result):
)
if not matched:
- mo = re.match("^\-([0-9]+)$", linespec)
+ mo = re.match(r"^\-([0-9]+)$", linespec)
if mo is not None:
matched = True
# print "Matched -<count>"
@@ -79,7 +79,7 @@ def parse_linespec(linespec, frame, result):
breakpoint = target.BreakpointCreateByLocation(file_name, line_number)
if not matched:
- mo = re.match("\*((0x)?([0-9a-f]+))$", linespec)
+ mo = re.match(r"\*((0x)?([0-9a-f]+))$", linespec)
if mo is not None:
matched = True
# print "Matched <address-expression>"
diff --git a/lldb/examples/python/performance.py b/lldb/examples/python/performance.py
index 869a0b061cf85..b86b5a52522e0 100755
--- a/lldb/examples/python/performance.py
+++ b/lldb/examples/python/performance.py
@@ -346,7 +346,7 @@ def __init__(self, pid):
def Measure(self):
output = subprocess.getoutput(self.command).split("\n")[-1]
- values = re.split("[-+\s]+", output)
+ values = re.split(r"[-+\s]+", output)
for idx, stat in enumerate(values):
multiplier = 1
if stat:
diff --git a/lldb/examples/python/symbolication.py b/lldb/examples/python/symbolication.py
index f6dcc8b9a7943..b16745ee963c9 100755
--- a/lldb/examples/python/symbolication.py
+++ b/lldb/examples/python/symbolication.py
@@ -177,9 +177,9 @@ class Section:
"""Class that represents an load address range"""
sect_info_regex = re.compile("(?P<name>[^=]+)=(?P<range>.*)")
- addr_regex = re.compile("^\s*(?P<start>0x[0-9A-Fa-f]+)\s*$")
+ addr_regex = re.compile(r"^\s*(?P<start>0x[0-9A-Fa-f]+)\s*$")
range_regex = re.compile(
- "^\s*(?P<start>0x[0-9A-Fa-f]+)\s*(?P<op>[-+])\s*(?P<end>0x[0-9A-Fa-f]+)\s*$"
+ r"^\s*(?P<start>0x[0-9A-Fa-f]+)\s*(?P<op>[-+])\s*(?P<end>0x[0-9A-Fa-f]+)\s*$"
)
def __init__(self, start_addr=None, end_addr=None, name=None):
@@ -557,7 +557,7 @@ def find_images_with_identifier(self, identifier):
if image.identifier == identifier:
images.append(image)
if len(images) == 0:
- regex_text = "^.*\.%s$" % (re.escape(identifier))
+ regex_text = r"^.*\.%s$" % (re.escape(identifier))
regex = re.compile(regex_text)
for image in self.images:
if regex.match(image.identifier):
diff --git a/lldb/packages/Python/lldbsuite/test/lldbpexpect.py b/lldb/packages/Python/lldbsuite/test/lldbpexpect.py
index 998a080565b6b..3279e1fd39f8c 100644
--- a/lldb/packages/Python/lldbsuite/test/lldbpexpect.py
+++ b/lldb/packages/Python/lldbsuite/test/lldbpexpect.py
@@ -104,4 +104,4 @@ def cursor_forward_escape_seq(self, chars_to_move):
Returns the escape sequence to move the cursor forward/right
by a certain amount of characters.
"""
- return b"\x1b\[" + str(chars_to_move).encode("utf-8") + b"C"
+ return b"\x1b\\[" + str(chars_to_move).encode("utf-8") + b"C"
diff --git a/lldb/packages/Python/lldbsuite/test/test_runner/process_control.py b/lldb/packages/Python/lldbsuite/test/test_runner/process_control.py
index 07c17993bc878..8ab219a92d99d 100644
--- a/lldb/packages/Python/lldbsuite/test/test_runner/process_control.py
+++ b/lldb/packages/Python/lldbsuite/test/test_runner/process_control.py
@@ -91,7 +91,7 @@ def timeout_to_seconds(timeout):
class ProcessHelper(object):
- """Provides an interface for accessing process-related functionality.
+ r"""Provides an interface for accessing process-related functionality.
This class provides a factory method that gives the caller a
platform-specific implementation instance of the class.
diff --git a/lldb/test/API/commands/command/backticks/TestBackticksInAlias.py b/lldb/test/API/commands/command/backticks/TestBackticksInAlias.py
index c31a08ac00182..2cb8d225d6d07 100644
--- a/lldb/test/API/commands/command/backticks/TestBackticksInAlias.py
+++ b/lldb/test/API/commands/command/backticks/TestBackticksInAlias.py
@@ -20,7 +20,7 @@ def test_backticks_in_alias(self):
interp = self.dbg.GetCommandInterpreter()
result = lldb.SBCommandReturnObject()
interp.HandleCommand(
- "command alias _test-argv-cmd expression -Z \`argc\` -- argv", result
+ r"command alias _test-argv-cmd expression -Z \`argc\` -- argv", result
)
self.assertCommandReturn(result, "Made the alias")
interp.HandleCommand("_test-argv-cmd", result)
@@ -28,7 +28,7 @@ def test_backticks_in_alias(self):
# Now try a harder case where we create this using an alias:
interp.HandleCommand(
- "command alias _test-argv-parray-cmd parray \`argc\` argv", result
+ r"command alias _test-argv-parray-cmd parray \`argc\` argv", result
)
self.assertCommandReturn(result, "Made the alias")
interp.HandleCommand("_test-argv-parray-cmd", result)
diff --git a/lldb/test/API/commands/expression/memory-allocation/TestMemoryAllocSettings.py b/lldb/test/API/commands/expression/memory-allocation/TestMemoryAllocSettings.py
index d27f07717affb..a82141a0792f2 100644
--- a/lldb/test/API/commands/expression/...
[truncated]
|
Two questions:
|
The valid escape sequences in Python are listed here: Invalid ones fixed here seem to be used for regular expression, re, e.g. I use flake8 for check.
No. We have choices to fix these:
I thought 2 is simple but actually it does not work for e.g.: --- a/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
+++ b/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
@@ -242,7 +242,7 @@ def main():
filename = None
lines_by_file = {}
for line in sys.stdin:
- match = re.search('^\+\+\+\ "?(.*?/){%s}([^ \t\n"]*)' % args.p, line)
+ match = re.search('^\\+\\+\\+\\ "?(.*?/){%s}([^ \t\n"]*)' % args.p, line)
if match:
filename = match.group(2)
if filename is None: Here So I manually fixed them. |
https://docs.python.org/3/reference/lexical_analysis.html#escape-sequences
adding raw string prefix |
I think you'll probably want to split this into multiple PRs, at least one per root folder in the monorepo. That will make a bunch of smaller PRs which will be easier to review and will also allow you to request review from people specifically responsible for those areas. And I think I would agree that using |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As per Aiden's suggestion, please split this up into smaller PRs, grouped by subproject.
No description provided.