Python3.12 is throwing syntax warnings in ovs-dpctl-top

[root@localhost ~]# python --version
Python 3.12.5
[root@localhost ~]# ovs-dpctl-top --help > /dev/null
/usr/bin/ovs-dpctl-top:392: SyntaxWarning: invalid escape sequence '\w'
  FIELDS_CMPND = re.compile("([\w]+)\((.+)\)")
/usr/bin/ovs-dpctl-top:394: SyntaxWarning: invalid escape sequence '\w'
  FIELDS_CMPND_ELEMENT = re.compile("([\w:]+)=([/\.\w:]+)")
/usr/bin/ovs-dpctl-top:395: SyntaxWarning: invalid escape sequence '\w'
  FIELDS_ELEMENT = re.compile("([\w]+):([-\.\w]+)")


The warning seems to be new to python3.12

Python 3.12.5 (main, Aug 23 2024, 00:00:00)
>>> import re
>>> re.compile("([\w]+)\((.+)\)")
<stdin>:1: SyntaxWarning: invalid escape sequence '\w'
re.compile('([\\w]+)\\((.+)\\)')
>>> re.compile(r"([\w]+)\((.+)\)")
re.compile('([\\w]+)\\((.+)\\)')

Python 3.11.4 (main, Jun  7 2023, 00:00:00)
>>> import re
>>> re.compile("([\w]+)\((.+)\)")
re.compile('([\\w]+)\\((.+)\\)')


Prepending the string with r tells python treat the string as a raw string
literal and to not try to scape \w, \(, etc, and gets rid of the warning

Signed-off-by: Michael Santana <[email protected]>
---
 utilities/ovs-dpctl-top.in | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/utilities/ovs-dpctl-top.in b/utilities/ovs-dpctl-top.in
index ec57eccd6..1708c2f37 100755
--- a/utilities/ovs-dpctl-top.in
+++ b/utilities/ovs-dpctl-top.in
@@ -389,10 +389,10 @@ def args_get():
 # Code to parse a single line in dump-flow
 ###
 # key(values)
-FIELDS_CMPND = re.compile("([\w]+)\((.+)\)")
+FIELDS_CMPND = re.compile(r"([\w]+)\((.+)\)")
 # key:value
-FIELDS_CMPND_ELEMENT = re.compile("([\w:]+)=([/\.\w:]+)")
-FIELDS_ELEMENT = re.compile("([\w]+):([-\.\w]+)")
+FIELDS_CMPND_ELEMENT = re.compile(r"([\w:]+)=([/\.\w:]+)")
+FIELDS_ELEMENT = re.compile(r"([\w]+):([-\.\w]+)")
 
 
 def flow_line_iter(line):
-- 
2.43.0

_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to