[PATCH] D158356: [lit] Use raw strings for backslash escapes to fix SyntaxWarnings

Michał Górny via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Aug 19 23:51:45 PDT 2023


mgorny created this revision.
mgorny added reviewers: ddunbar, mstorsjo, thieta.
Herald added a subscriber: delcypher.
Herald added a project: All.
mgorny requested review of this revision.
Herald added a project: LLVM.

Use raw strings instead of regular strings when escapes are used for
regex matches or arbitrary letters rather than C-style characters.
This fixes `SyntaxWarning`s:

  TestRunner.py:205: SyntaxWarning: invalid escape sequence '\c'
    """
  TestRunner.py:1566: SyntaxWarning: invalid escape sequence '\s'
    match = _caching_re_compile("^\s*%else\s*(%{)?").search(ln)


https://reviews.llvm.org/D158356

Files:
  llvm/utils/lit/lit/TestRunner.py


Index: llvm/utils/lit/lit/TestRunner.py
===================================================================
--- llvm/utils/lit/lit/TestRunner.py
+++ llvm/utils/lit/lit/TestRunner.py
@@ -202,7 +202,7 @@
 
 
 def quote_windows_command(seq):
-    """
+    r"""
     Reimplement Python's private subprocess.list2cmdline for MSys compatibility
 
     Based on CPython implementation here:
@@ -1563,7 +1563,7 @@
             return cond, ln
 
         def tryParseElse(ln):
-            match = _caching_re_compile("^\s*%else\s*(%{)?").search(ln)
+            match = _caching_re_compile(r"^\s*%else\s*(%{)?").search(ln)
             if not match:
                 return False, ln
             if not match.group(1):


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D158356.551806.patch
Type: text/x-patch
Size: 712 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230820/1cbfc825/attachment.bin>


More information about the llvm-commits mailing list