]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
patman: Resolve python string vs. regex escaping syntax
authorBrian Norris <computersforpeace@gmail.com>
Fri, 26 Jul 2024 19:02:33 +0000 (12:02 -0700)
committerSimon Glass <sjg@chromium.org>
Sun, 1 Sep 2024 17:05:43 +0000 (11:05 -0600)
Python strings have their own notion of backslash-escaping, and that can
conflict with the intentions for strings passed to the 're' module. In
particular, I get warnings like this:

tools/patman/../patman/commit.py:9: SyntaxWarning: invalid escape sequence '\s'
  re_subject_tag = re.compile('([^:\s]*):\s*(.*)')

We should use a raw string (r'...') so that all escaping is passed into
the regex module, not interpreted within the string itself.

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
tools/patman/commit.py
tools/patman/patchstream.py

index 684225c0e60d41552742a49da4c268db360bbb43..ce37a3d95eb97d9b0635cadea27291d9a374a159 100644 (file)
@@ -6,7 +6,7 @@ import collections
 import re
 
 # Separates a tag: at the beginning of the subject from the rest of it
-re_subject_tag = re.compile('([^:\s]*):\s*(.*)')
+re_subject_tag = re.compile(r'([^:\s]*):\s*(.*)')
 
 class Commit:
     """Holds information about a single commit/patch in the series.
index a09ae9c73714dbd068e5b6f8f99e93f2c787ae70..4955f6aaab995a7560e5546dedb8a85c431eb437 100644 (file)
@@ -48,7 +48,7 @@ RE_TAG = re.compile('^(Tested-by|Acked-by|Reviewed-by|Patch-cc|Fixes): (.*)')
 RE_COMMIT = re.compile('^commit ([0-9a-f]*)$')
 
 # We detect these since checkpatch doesn't always do it
-RE_SPACE_BEFORE_TAB = re.compile('^[+].* \t')
+RE_SPACE_BEFORE_TAB = re.compile(r'^[+].* \t')
 
 # Match indented lines for changes
 RE_LEADING_WHITESPACE = re.compile(r'^\s')