Skip to content

Commit 6f214ed

Browse files
committed
fix(python): fix invalid escape sequences
1 parent 079fdef commit 6f214ed

File tree

100 files changed

+321
-321
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+321
-321
lines changed

.github/workflows/version-check.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77

88
def get_version_from_tag(tag):
9-
m = re.match("llvmorg-([0-9]+)\.([0-9]+)\.([0-9]+)(-rc[0-9]+)?$", tag)
9+
m = re.match(r"llvmorg-([0-9]+)\.([0-9]+)\.([0-9]+)(-rc[0-9]+)?$", tag)
1010
if m:
1111
if m.lastindex == 4:
1212
# We have an rc tag.

clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ def main():
242242
filename = None
243243
lines_by_file = {}
244244
for line in sys.stdin:
245-
match = re.search('^\+\+\+\ "?(.*?/){%s}([^ \t\n"]*)' % args.p, line)
245+
match = re.search('^\\+\\+\\+\\ "?(.*?/){%s}([^ \t\n"]*)' % args.p, line)
246246
if match:
247247
filename = match.group(2)
248248
if filename is None:
@@ -255,7 +255,7 @@ def main():
255255
if not re.match("^%s$" % args.iregex, filename, re.IGNORECASE):
256256
continue
257257

258-
match = re.search("^@@.*\+(\d+)(,(\d+))?", line)
258+
match = re.search(r"^@@.*\+(\d+)(,(\d+))?", line)
259259
if match:
260260
start_line = int(match.group(1))
261261
line_count = 1

clang-tools-extra/docs/clang-tidy/checks/gen-static-analyzer-docs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def get_checkers(checkers_td, checkers_rst):
5959
"clang-analyzer-" + checker_package_prefix + "." + checker_name
6060
)
6161
anchor_url = re.sub(
62-
"\.", "-", checker_package_prefix + "." + checker_name
62+
r"\.", "-", checker_package_prefix + "." + checker_name
6363
).lower()
6464

6565
if not hidden and "alpha" not in full_package_name.lower():

clang/docs/tools/dump_ast_matchers.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,11 @@ def extract_result_types(comment):
8686
parsed.
8787
"""
8888
result_types = []
89-
m = re.search(r"Usable as: Any Matcher[\s\n]*$", comment, re.S)
89+
m = re.search("Usable as: Any Matcher[\\s\n]*$", comment, re.S)
9090
if m:
9191
return ["*"]
9292
while True:
93-
m = re.match(r"^(.*)Matcher<([^>]+)>\s*,?[\s\n]*$", comment, re.S)
93+
m = re.match("^(.*)Matcher<([^>]+)>\\s*,?[\\s\n]*$", comment, re.S)
9494
if not m:
9595
if re.search(r"Usable as:\s*$", comment):
9696
return result_types
@@ -101,9 +101,9 @@ def extract_result_types(comment):
101101

102102

103103
def strip_doxygen(comment):
104-
"""Returns the given comment without \-escaped words."""
104+
r"""Returns the given comment without \-escaped words."""
105105
# If there is only a doxygen keyword in the line, delete the whole line.
106-
comment = re.sub(r"^\\[^\s]+\n", r"", comment, flags=re.M)
106+
comment = re.sub("^\\\\[^\\s]+\n", r"", comment, flags=re.M)
107107

108108
# If there is a doxygen \see command, change the \see prefix into "See also:".
109109
# 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):
236236

237237
# Parse the various matcher definition macros.
238238
m = re.match(
239-
""".*AST_TYPE(LOC)?_TRAVERSE_MATCHER(?:_DECL)?\(
239+
r""".*AST_TYPE(LOC)?_TRAVERSE_MATCHER(?:_DECL)?\(
240240
\s*([^\s,]+\s*),
241241
\s*(?:[^\s,]+\s*),
242242
\s*AST_POLYMORPHIC_SUPPORTED_TYPES\(([^)]*)\)

clang/test/Analysis/check-analyzer-fixit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def run_test_once(args, extra_args):
5555
# themselves. We need to keep the comments to preserve line numbers while
5656
# avoiding empty lines which could potentially trigger formatting-related
5757
# checks.
58-
cleaned_test = re.sub("// *CHECK-[A-Z0-9\-]*:[^\r\n]*", "//", input_text)
58+
cleaned_test = re.sub("// *CHECK-[A-Z0-9\\-]*:[^\r\n]*", "//", input_text)
5959
write_file(temp_file_name, cleaned_test)
6060

6161
original_file_name = temp_file_name + ".orig"

compiler-rt/lib/asan/scripts/asan_symbolize.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ def symbolize(self, addr, binary, offset):
316316
# * For C functions atos omits parentheses and argument types.
317317
# * For C++ functions the function name (i.e., `foo` above) may contain
318318
# templates which may contain parentheses.
319-
match = re.match("^(.*) \(in (.*)\) \((.*:\d*)\)$", atos_line)
319+
match = re.match(r"^(.*) \(in (.*)\) \((.*:\d*)\)$", atos_line)
320320
logging.debug("atos_line: %s", atos_line)
321321
if match:
322322
function_name = match.group(1)
@@ -541,7 +541,7 @@ def process_line_posix(self, line):
541541
# names in the regex because it could be an
542542
# Objective-C or C++ demangled name.
543543
stack_trace_line_format = (
544-
"^( *#([0-9]+) *)(0x[0-9a-f]+) *(?:in *.+)? *\((.*)\+(0x[0-9a-f]+)\)"
544+
r"^( *#([0-9]+) *)(0x[0-9a-f]+) *(?:in *.+)? *\((.*)\+(0x[0-9a-f]+)\)"
545545
)
546546
match = re.match(stack_trace_line_format, line)
547547
if not match:

cross-project-tests/debuginfo-tests/dexter/dex/command/ParseCommand.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def get_address_object(address_name: str, offset: int = 0):
128128

129129

130130
def _search_line_for_cmd_start(line: str, start: int, valid_commands: dict) -> int:
131-
"""Scan `line` for a string matching any key in `valid_commands`.
131+
r"""Scan `line` for a string matching any key in `valid_commands`.
132132
133133
Start searching from `start`.
134134
Commands escaped with `\` (E.g. `\DexLabel('a')`) are ignored.
@@ -543,7 +543,7 @@ def test_parse_share_line(self):
543543
def test_parse_escaped(self):
544544
"""Escaped commands are ignored."""
545545

546-
lines = ['words \MockCmd("IGNORED") words words words\n']
546+
lines = ['words \\MockCmd("IGNORED") words words words\n']
547547

548548
values = self._find_all_mock_values_in_lines(lines)
549549

cross-project-tests/lit.cfg.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ def can_target_host():
226226
xcode_lldb_vers = subprocess.check_output(["xcrun", "lldb", "--version"]).decode(
227227
"utf-8"
228228
)
229-
match = re.search("lldb-(\d+)", xcode_lldb_vers)
229+
match = re.search(r"lldb-(\d+)", xcode_lldb_vers)
230230
if match:
231231
apple_lldb_vers = int(match.group(1))
232232
if apple_lldb_vers < 1000:
@@ -250,7 +250,7 @@ def get_gdb_version_string():
250250
if len(gdb_vers_lines) < 1:
251251
print("Unkown GDB version format (too few lines)", file=sys.stderr)
252252
return None
253-
match = re.search("GNU gdb \(.*?\) ((\d|\.)+)", gdb_vers_lines[0].strip())
253+
match = re.search(r"GNU gdb \(.*?\) ((\d|\.)+)", gdb_vers_lines[0].strip())
254254
if match is None:
255255
print(f"Unkown GDB version format: {gdb_vers_lines[0]}", file=sys.stderr)
256256
return None
@@ -264,7 +264,7 @@ def get_clang_default_dwarf_version_string(triple):
264264
# Get the flags passed by the driver and look for -dwarf-version.
265265
cmd = f'{llvm_config.use_llvm_tool("clang")} -g -xc -c - -v -### --target={triple}'
266266
stderr = subprocess.run(cmd.split(), stderr=subprocess.PIPE).stderr.decode()
267-
match = re.search("-dwarf-version=(\d+)", stderr)
267+
match = re.search(r"-dwarf-version=(\d+)", stderr)
268268
if match is None:
269269
print("Cannot determine default dwarf version", file=sys.stderr)
270270
return None

libcxx/test/libcxx/transitive_includes.gen.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
continue
6060

6161
# Escape slashes for the awk command below
62-
escaped_header = header.replace('/', '\/')
62+
escaped_header = header.replace('/', r'\/')
6363

6464
print(f"""\
6565
//--- {header}.sh.cpp

libcxx/utils/generate_escaped_output_table.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def compactPropertyRanges(input: list[PropertyRange]) -> list[PropertyRange]:
8484
return result
8585

8686

87-
DATA_ARRAY_TEMPLATE = """
87+
DATA_ARRAY_TEMPLATE = r"""
8888
/// The entries of the characters to escape in format's debug string.
8989
///
9090
/// Contains the entries for [format.string.escaped]/2.2.1.2.1

libcxx/utils/generate_width_estimation_table.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def compactPropertyRanges(input: list[PropertyRange]) -> list[PropertyRange]:
9999
return result
100100

101101

102-
DATA_ARRAY_TEMPLATE = """
102+
DATA_ARRAY_TEMPLATE = r"""
103103
/// The entries of the characters with an estimated width of 2.
104104
///
105105
/// Contains the entries for [format.string.std]/12

lld/test/MachO/tools/validate-unwind-info.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212

1313
def main():
14-
hex = "[a-f\d]"
14+
hex = r"[a-f\d]"
1515
hex8 = hex + "{8}"
1616

1717
parser = argparse.ArgumentParser(description=__doc__)

lld/utils/benchmark.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def __str__(self):
5151
def getBenchmarks():
5252
ret = []
5353
for i in glob.glob("*/response*.txt"):
54-
m = re.match("response-(.*)\.txt", os.path.basename(i))
54+
m = re.match(r"response-(.*)\.txt", os.path.basename(i))
5555
variant = m.groups()[0] if m else None
5656
ret.append(Bench(os.path.dirname(i), variant))
5757
return ret

lldb/examples/python/crashlog.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ class DarwinImage(symbolication.Image):
294294
except:
295295
dsymForUUIDBinary = ""
296296

297-
dwarfdump_uuid_regex = re.compile("UUID: ([-0-9a-fA-F]+) \(([^\(]+)\) .*")
297+
dwarfdump_uuid_regex = re.compile(r"UUID: ([-0-9a-fA-F]+) \(([^\(]+)\) .*")
298298

299299
def __init__(
300300
self, text_addr_lo, text_addr_hi, identifier, version, uuid, path, verbose
@@ -499,7 +499,7 @@ def find_image_with_identifier(self, identifier):
499499
for image in self.images:
500500
if image.identifier == identifier:
501501
return image
502-
regex_text = "^.*\.%s$" % (re.escape(identifier))
502+
regex_text = r"^.*\.%s$" % (re.escape(identifier))
503503
regex = re.compile(regex_text)
504504
for image in self.images:
505505
if regex.match(image.identifier):
@@ -919,7 +919,7 @@ def get(cls):
919919
version = r"(?:" + super().version + r"\s+)?"
920920
address = r"(0x[0-9a-fA-F]{4,})" # 4 digits or more
921921

922-
symbol = """
922+
symbol = r"""
923923
(?:
924924
[ ]+
925925
(?P<symbol>.+)
@@ -1089,7 +1089,7 @@ def parse_normal(self, line):
10891089
self.crashlog.process_identifier = line[11:].strip()
10901090
elif line.startswith("Version:"):
10911091
version_string = line[8:].strip()
1092-
matched_pair = re.search("(.+)\((.+)\)", version_string)
1092+
matched_pair = re.search(r"(.+)\((.+)\)", version_string)
10931093
if matched_pair:
10941094
self.crashlog.process_version = matched_pair.group(1)
10951095
self.crashlog.process_compatability_version = matched_pair.group(2)

lldb/examples/python/delta.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def parse_log_file(file, options):
9999
print("# Log file: '%s'" % file)
100100
print("#----------------------------------------------------------------------")
101101

102-
timestamp_regex = re.compile("(\s*)([1-9][0-9]+\.[0-9]+)([^0-9].*)$")
102+
timestamp_regex = re.compile(r"(\s*)([1-9][0-9]+\.[0-9]+)([^0-9].*)$")
103103

104104
base_time = 0.0
105105
last_time = 0.0

lldb/examples/python/gdbremote.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1537,12 +1537,12 @@ def parse_gdb_log(file, options):
15371537
a long time during a preset set of debugger commands."""
15381538

15391539
tricky_commands = ["qRegisterInfo"]
1540-
timestamp_regex = re.compile("(\s*)([1-9][0-9]+\.[0-9]+)([^0-9].*)$")
1540+
timestamp_regex = re.compile(r"(\s*)([1-9][0-9]+\.[0-9]+)([^0-9].*)$")
15411541
packet_name_regex = re.compile("([A-Za-z_]+)[^a-z]")
15421542
packet_transmit_name_regex = re.compile(
15431543
"(?P<direction>send|read) packet: (?P<packet>.*)"
15441544
)
1545-
packet_contents_name_regex = re.compile("\$([^#]*)#[0-9a-fA-F]{2}")
1545+
packet_contents_name_regex = re.compile(r"\$([^#]*)#[0-9a-fA-F]{2}")
15461546
packet_checksum_regex = re.compile(".*#[0-9a-fA-F]{2}$")
15471547
packet_names_regex_str = "(" + "|".join(gdb_remote_commands.keys()) + ")(.*)"
15481548
packet_names_regex = re.compile(packet_names_regex_str)

lldb/examples/python/jump.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def parse_linespec(linespec, frame, result):
3838
)
3939

4040
if not matched:
41-
mo = re.match("^\+([0-9]+)$", linespec)
41+
mo = re.match(r"^\+([0-9]+)$", linespec)
4242
if mo is not None:
4343
matched = True
4444
# print "Matched +<count>"
@@ -54,7 +54,7 @@ def parse_linespec(linespec, frame, result):
5454
)
5555

5656
if not matched:
57-
mo = re.match("^\-([0-9]+)$", linespec)
57+
mo = re.match(r"^\-([0-9]+)$", linespec)
5858
if mo is not None:
5959
matched = True
6060
# print "Matched -<count>"
@@ -79,7 +79,7 @@ def parse_linespec(linespec, frame, result):
7979
breakpoint = target.BreakpointCreateByLocation(file_name, line_number)
8080

8181
if not matched:
82-
mo = re.match("\*((0x)?([0-9a-f]+))$", linespec)
82+
mo = re.match(r"\*((0x)?([0-9a-f]+))$", linespec)
8383
if mo is not None:
8484
matched = True
8585
# print "Matched <address-expression>"

lldb/examples/python/performance.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ def __init__(self, pid):
346346

347347
def Measure(self):
348348
output = subprocess.getoutput(self.command).split("\n")[-1]
349-
values = re.split("[-+\s]+", output)
349+
values = re.split(r"[-+\s]+", output)
350350
for idx, stat in enumerate(values):
351351
multiplier = 1
352352
if stat:

lldb/examples/python/symbolication.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,9 @@ class Section:
177177
"""Class that represents an load address range"""
178178

179179
sect_info_regex = re.compile("(?P<name>[^=]+)=(?P<range>.*)")
180-
addr_regex = re.compile("^\s*(?P<start>0x[0-9A-Fa-f]+)\s*$")
180+
addr_regex = re.compile(r"^\s*(?P<start>0x[0-9A-Fa-f]+)\s*$")
181181
range_regex = re.compile(
182-
"^\s*(?P<start>0x[0-9A-Fa-f]+)\s*(?P<op>[-+])\s*(?P<end>0x[0-9A-Fa-f]+)\s*$"
182+
r"^\s*(?P<start>0x[0-9A-Fa-f]+)\s*(?P<op>[-+])\s*(?P<end>0x[0-9A-Fa-f]+)\s*$"
183183
)
184184

185185
def __init__(self, start_addr=None, end_addr=None, name=None):
@@ -557,7 +557,7 @@ def find_images_with_identifier(self, identifier):
557557
if image.identifier == identifier:
558558
images.append(image)
559559
if len(images) == 0:
560-
regex_text = "^.*\.%s$" % (re.escape(identifier))
560+
regex_text = r"^.*\.%s$" % (re.escape(identifier))
561561
regex = re.compile(regex_text)
562562
for image in self.images:
563563
if regex.match(image.identifier):

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,4 @@ def cursor_forward_escape_seq(self, chars_to_move):
104104
Returns the escape sequence to move the cursor forward/right
105105
by a certain amount of characters.
106106
"""
107-
return b"\x1b\[" + str(chars_to_move).encode("utf-8") + b"C"
107+
return b"\x1b\\[" + str(chars_to_move).encode("utf-8") + b"C"

lldb/packages/Python/lldbsuite/test/test_runner/process_control.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def timeout_to_seconds(timeout):
9191

9292

9393
class ProcessHelper(object):
94-
"""Provides an interface for accessing process-related functionality.
94+
r"""Provides an interface for accessing process-related functionality.
9595
9696
This class provides a factory method that gives the caller a
9797
platform-specific implementation instance of the class.

lldb/test/API/commands/command/backticks/TestBackticksInAlias.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ def test_backticks_in_alias(self):
2020
interp = self.dbg.GetCommandInterpreter()
2121
result = lldb.SBCommandReturnObject()
2222
interp.HandleCommand(
23-
"command alias _test-argv-cmd expression -Z \`argc\` -- argv", result
23+
r"command alias _test-argv-cmd expression -Z \`argc\` -- argv", result
2424
)
2525
self.assertCommandReturn(result, "Made the alias")
2626
interp.HandleCommand("_test-argv-cmd", result)
2727
self.assertCommandReturn(result, "The alias worked")
2828

2929
# Now try a harder case where we create this using an alias:
3030
interp.HandleCommand(
31-
"command alias _test-argv-parray-cmd parray \`argc\` argv", result
31+
r"command alias _test-argv-parray-cmd parray \`argc\` argv", result
3232
)
3333
self.assertCommandReturn(result, "Made the alias")
3434
interp.HandleCommand("_test-argv-parray-cmd", result)

lldb/test/API/commands/expression/memory-allocation/TestMemoryAllocSettings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def test(self):
3030
alloc0 = re.search("^.*IRMemoryMap::Malloc.+?0xdead0000.*$", log, re.MULTILINE)
3131
# Malloc adds additional bytes to allocation size, hence 10007
3232
alloc1 = re.search(
33-
"^.*IRMemoryMap::Malloc\s*?\(10007.+?0xdead1000.*$", log, re.MULTILINE
33+
r"^.*IRMemoryMap::Malloc\s*?\(10007.+?0xdead1000.*$", log, re.MULTILINE
3434
)
3535
self.assertTrue(alloc0, "Couldn't find an allocation at a given address.")
3636
self.assertTrue(

lldb/test/API/commands/expression/test/TestExprs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def build_and_run(self):
5050
def test_floating_point_expr_commands(self):
5151
self.build_and_run()
5252

53-
self.expect("expression 2.234f", patterns=["\(float\) \$.* = 2\.234"])
53+
self.expect("expression 2.234f", patterns=[r"\(float\) \$.* = 2\.234"])
5454
# (float) $2 = 2.234
5555

5656
def test_many_expr_commands(self):

lldb/test/API/commands/gui/expand-threads-tree/TestGuiExpandThreadsTree.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def test_gui(self):
4848
self.child.expect_exact("Threads")
4949

5050
# The main thread should be expanded.
51-
self.child.expect("#\d+: main")
51+
self.child.expect(r"#\d+: main")
5252

5353
# Quit the GUI
5454
self.child.send(escape_key)

lldb/test/API/commands/help/TestHelp.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -349,13 +349,13 @@ def test_help_show_tags(self):
349349
self.expect(
350350
"help memory read",
351351
patterns=[
352-
"--show-tags\n\s+Include memory tags in output "
353-
"\(does not apply to binary output\)."
352+
"--show-tags\n\\s+Include memory tags in output "
353+
"\\(does not apply to binary output\\)."
354354
],
355355
)
356356
self.expect(
357357
"help memory find",
358-
patterns=["--show-tags\n\s+Include memory tags in output."],
358+
patterns=["--show-tags\n\\s+Include memory tags in output."],
359359
)
360360

361361
@no_debug_info_test

lldb/test/API/commands/process/launch-with-shellexpand/TestLaunchWithShellExpand.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def test(self):
9393

9494
self.runCmd("process kill")
9595

96-
self.runCmd("process launch -X true -w %s -- foo\ bar" % (self.getBuildDir()))
96+
self.runCmd(r"process launch -X true -w %s -- foo\ bar" % (self.getBuildDir()))
9797

9898
process = self.process()
9999

0 commit comments

Comments
 (0)