Skip to content

Commit e9ffeea

Browse files
committed
python: use raw strings for regex
Changed in python version 3.12: A backslash-character pair that is not a valid escape sequence now generates a SyntaxWarning, instead of DeprecationWarning. For example, re.compile("\d+\. \d+") now emits a SyntaxWarning ("\d" is an invalid escape sequence, use raw strings for regular expression: re.compile(r"\d+\.\d+")). In a future Python version, SyntaxError will eventually be raised, instead of SyntaxWarning. (Contributed by Victor Stinner in gh-98401.) Closes: #97815 See-also: https://docs.python.org/3/reference/lexical_analysis.html#escape-sequences Signed-off-by: Paul Zander <[email protected]>
1 parent 1193f7d commit e9ffeea

File tree

98 files changed

+325
-325
lines changed

Some content is hidden

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

98 files changed

+325
-325
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/docs/tools/dump_ast_matchers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ 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.
106106
comment = re.sub(r"^\\[^\s]+\n", r"", comment, flags=re.M)
107107

@@ -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(r"// *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 = [r'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
@@ -223,7 +223,7 @@ def can_target_host():
223223
xcode_lldb_vers = subprocess.check_output(["xcrun", "lldb", "--version"]).decode(
224224
"utf-8"
225225
)
226-
match = re.search("lldb-(\d+)", xcode_lldb_vers)
226+
match = re.search(r"lldb-(\d+)", xcode_lldb_vers)
227227
if match:
228228
apple_lldb_vers = int(match.group(1))
229229
if apple_lldb_vers < 1000:
@@ -247,7 +247,7 @@ def get_gdb_version_string():
247247
if len(gdb_vers_lines) < 1:
248248
print("Unkown GDB version format (too few lines)", file=sys.stderr)
249249
return None
250-
match = re.search("GNU gdb \(.*?\) ((\d|\.)+)", gdb_vers_lines[0].strip())
250+
match = re.search(r"GNU gdb \(.*?\) ((\d|\.)+)", gdb_vers_lines[0].strip())
251251
if match is None:
252252
print(f"Unkown GDB version format: {gdb_vers_lines[0]}", file=sys.stderr)
253253
return None
@@ -261,7 +261,7 @@ def get_clang_default_dwarf_version_string(triple):
261261
# Get the flags passed by the driver and look for -dwarf-version.
262262
cmd = f'{llvm_config.use_llvm_tool("clang")} -g -xc -c - -v -### --target={triple}'
263263
stderr = subprocess.run(cmd.split(), stderr=subprocess.PIPE).stderr.decode()
264-
match = re.search("-dwarf-version=(\d+)", stderr)
264+
match = re.search(r"-dwarf-version=(\d+)", stderr)
265265
if match is None:
266266
print("Cannot determine default dwarf version", file=sys.stderr)
267267
return None

libcxx/utils/synchronize_csv_status_files.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ def sync_csv(rows: List[Tuple], from_github: List[PaperInfo]) -> List[Tuple]:
284284
results.append(gh.for_printing())
285285
continue
286286
elif paper.status != gh.status:
287-
print(f"We found a CSV row and a Github issue with different statuses:\nrow: {row}\Github issue: {gh}")
287+
print(rf"We found a CSV row and a Github issue with different statuses:\nrow: {row}\Github issue: {gh}")
288288
results.append(row)
289289

290290
return results

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
@@ -296,7 +296,7 @@ class DarwinImage(symbolication.Image):
296296
except:
297297
dsymForUUIDBinary = ""
298298

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

301301
def __init__(
302302
self, text_addr_lo, text_addr_hi, identifier, version, uuid, path, verbose
@@ -501,7 +501,7 @@ def find_image_with_identifier(self, identifier):
501501
for image in self.images:
502502
if image.identifier == identifier:
503503
return image
504-
regex_text = "^.*\.%s$" % (re.escape(identifier))
504+
regex_text = r"^.*\.%s$" % (re.escape(identifier))
505505
regex = re.compile(regex_text)
506506
for image in self.images:
507507
if regex.match(image.identifier):
@@ -925,7 +925,7 @@ def get(cls):
925925
version = r"(?:" + super().version + r"\s+)?"
926926
address = r"(0x[0-9a-fA-F]{4,})" # 4 digits or more
927927

928-
symbol = """
928+
symbol = r"""
929929
(?:
930930
[ ]+
931931
(?P<symbol>.+)
@@ -1095,7 +1095,7 @@ def parse_normal(self, line):
10951095
self.crashlog.process_identifier = line[11:].strip()
10961096
elif line.startswith("Version:"):
10971097
version_string = line[8:].strip()
1098-
matched_pair = re.search("(.+)\((.+)\)", version_string)
1098+
matched_pair = re.search(r"(.+)\((.+)\)", version_string)
10991099
if matched_pair:
11001100
self.crashlog.process_version = matched_pair.group(1)
11011101
self.crashlog.process_compatability_version = matched_pair.group(2)

0 commit comments

Comments
 (0)