namhyung / uftrace

Function graph tracer for C/C++/Rust/Python
https://uftrace.github.io/slide/
GNU General Public License v2.0
2.92k stars 419 forks source link

Fix Python SyntaxWarning on invalid escape sequence in the tests scripts #1907

Closed AmeyaVS closed 3 months ago

AmeyaVS commented 3 months ago

Fixes the following SyntaxWarning: from the Python Interpreter:

uftrace/tests/./runtest.py:328: SyntaxWarning: invalid escape sequence '\['
  pid_patt = re.compile('[^[]+\[ *(\d+)\] |')

uftrace/tests/./runtest.py:496: SyntaxWarning: invalid escape sequence '\|'
  + '-->\|(?P<call_num>\d+)\|\s+(?P<end_depth>\d+)_(?P<end_id>\d+)\[\"(?P<end_name>\S+)\"\];', ln)

uftrace/tests/t230_graph_task.py:39: SyntaxWarning: invalid escape sequence '\['
  line = re.sub('\[\d+\]', 'TID', line)
namhyung commented 3 months ago

How did you get this warning?

AmeyaVS commented 3 months ago

Updated the test: prefix to the commit message.

AmeyaVS commented 3 months ago

How did you get this warning?

I am actually on a system with pretty recent Python 3.12, and it complains on escaped strings to be converted to raw strings.

AmeyaVS commented 3 months ago

Here's a reference for traceability from docs.python.org: https://docs.python.org/3/whatsnew/3.12.html#other-language-changes

A backslash-character pair that is not a valid escape sequence now generates a SyntaxWarning, instead of DeprecationWarning. For example, re.compile("\d+.\d+") now emits a SyntaxWarning ("\d" is an invalid escape sequence, use raw strings for regular expression: re.compile(r"\d+.\d+")). In a future Python version, SyntaxError will eventually be raised, instead of SyntaxWarning. (Contributed by Victor Stinner in gh-98401.)