Skip to contentSkip to conversation

xen/x86: Fix Syntax warning in gen-cpuid.py

PATCH In review Jason Andryuk 2 participants 2 messages Apr 26, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen/x86: Fix Syntax warning in gen-cpuid.py

Python 3.12.2 warns:

xen/tools/gen-cpuid.py:50: SyntaxWarning: invalid escape sequence '\s'
"\s+([\s\d]+\*[\s\d]+\+[\s\d]+)\)"
xen/tools/gen-cpuid.py:51: SyntaxWarning: invalid escape sequence '\s'
"\s+/\*([\w!]*) .*$")

Specify the strings as raw strings so '\s' is read as literal '\' + 's'. This avoids escaping all the '\'s in the strings.

---
 xen/tools/gen-cpuid.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
xen/tools/gen-cpuid.py +2 -2
index bf3f9ec01e..dadeb33080 100755
@@ -47,8 +47,8 @@ def parse_definitions(state):
     """
     feat_regex = re.compile(
         r"^XEN_CPUFEATURE\(([A-Z0-9_]+),"
-        "\s+([\s\d]+\*[\s\d]+\+[\s\d]+)\)"
-        "\s+/\*([\w!]*) .*$")
+        r"\s+([\s\d]+\*[\s\d]+\+[\s\d]+)\)"
+        r"\s+/\*([\w!]*) .*$")
 
     word_regex = re.compile(
         r"^/\* .* word (\d*) \*/$")
Signature · 1 line
2.44.0
Acked-by on v1 1/1
#1 lore raw
Quoted 11 lines · Jason Andryuk

Python 3.12.2 warns:

xen/tools/gen-cpuid.py:50: SyntaxWarning: invalid escape sequence '\s'
"\s+([\s\d]+\*[\s\d]+\+[\s\d]+)\)"
xen/tools/gen-cpuid.py:51: SyntaxWarning: invalid escape sequence '\s'
"\s+/\*([\w!]*) .*$")

Specify the strings as raw strings so '\s' is read as literal '\' + 's'. This avoids escaping all the '\'s in the strings.

That's something I didn't know about how python does string concatenation.  I was expecting the whole string to be considered raw, not just the first line.

I'll rebase my pending change altering the regex over this.