r353707 - [tools] Fix python DeprecationWarning: invalid escape sequence

Serge Guelton via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 11 07:03:18 PST 2019


Author: serge_sans_paille
Date: Mon Feb 11 07:03:17 2019
New Revision: 353707

URL: http://llvm.org/viewvc/llvm-project?rev=353707&view=rev
Log:
[tools] Fix python DeprecationWarning: invalid escape sequence

The python documentation says "it’s highly recommended that you use raw strings for all but the simplest expressions." (https://docs.python.org/3/library/re.html)

So do that with the attached patch generated by

    sed -i -e "s/re.search('/re.search(r'/g" $(git grep -l 're.search(')

The warning can be seen in e.g. python3.7:

    $ python3.7 -Wd
    >>> import re; re.search('\s', '')
    <stdin>:1: DeprecationWarning: invalid escape sequence \s

Commited on behalf of Marco Falke.
Differential Revision: https://reviews.llvm.org/D57528

Modified:
    cfe/trunk/tools/clang-format/clang-format-diff.py
    cfe/trunk/tools/scan-build-py/libscanbuild/analyze.py
    cfe/trunk/tools/scan-build/bin/set-xcode-analyzer

Modified: cfe/trunk/tools/clang-format/clang-format-diff.py
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-format/clang-format-diff.py?rev=353707&r1=353706&r2=353707&view=diff
==============================================================================
--- cfe/trunk/tools/clang-format/clang-format-diff.py (original)
+++ cfe/trunk/tools/clang-format/clang-format-diff.py Mon Feb 11 07:03:17 2019
@@ -66,7 +66,7 @@ def main():
   filename = None
   lines_by_file = {}
   for line in sys.stdin:
-    match = re.search('^\+\+\+\ (.*?/){%s}(\S*)' % args.p, line)
+    match = re.search(r'^\+\+\+\ (.*?/){%s}(\S*)' % args.p, line)
     if match:
       filename = match.group(2)
     if filename == None:
@@ -79,7 +79,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

Modified: cfe/trunk/tools/scan-build-py/libscanbuild/analyze.py
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/scan-build-py/libscanbuild/analyze.py?rev=353707&r1=353706&r2=353707&view=diff
==============================================================================
--- cfe/trunk/tools/scan-build-py/libscanbuild/analyze.py (original)
+++ cfe/trunk/tools/scan-build-py/libscanbuild/analyze.py Mon Feb 11 07:03:17 2019
@@ -97,7 +97,7 @@ def need_analyzer(args):
     when compiler wrappers are used. That's the moment when build setup
     check the compiler and capture the location for the build process. """
 
-    return len(args) and not re.search('configure|autogen', args[0])
+    return len(args) and not re.search(r'configure|autogen', args[0])
 
 
 def prefix_with(constant, pieces):

Modified: cfe/trunk/tools/scan-build/bin/set-xcode-analyzer
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/scan-build/bin/set-xcode-analyzer?rev=353707&r1=353706&r2=353707&view=diff
==============================================================================
--- cfe/trunk/tools/scan-build/bin/set-xcode-analyzer (original)
+++ cfe/trunk/tools/scan-build/bin/set-xcode-analyzer Mon Feb 11 07:03:17 2019
@@ -42,7 +42,7 @@ def ModifySpec(path, isBuiltinAnalyzer,
         if line.find("Static Analyzer") >= 0:
           foundAnalyzer = True
       else:
-        m = re.search('^(\s*ExecPath\s*=\s*")', line)
+        m = re.search(r'^(\s*ExecPath\s*=\s*")', line)
         if m:
           line = "".join([m.group(0), pathToChecker, '";\n'])
           # Do not modify further ExecPath's later in the xcspec.




More information about the cfe-commits mailing list