fix(util): use raw strings for regex patterns (W605 invalid escapes) - #102
Open
randomizedcoder wants to merge 1 commit into
Open
randomizedcoder wants to merge 1 commit into
randomizedcoder wants to merge 1 commit into
Conversation
Several regex string literals in the util/ trace-analysis scripts used
sequences like '\[', '\]', '\(', '\)' and '\+' inside ordinary (non-raw)
string literals. Python treats these as invalid escape sequences: they
currently evaluate to the intended backslash-plus-char by accident, but
emit a DeprecationWarning/SyntaxWarning and are slated to become errors
in a future Python. ruff flags every one as W605.
Convert the affected literals to raw strings (r'...'). Every conversion
is behavior-preserving: the evaluated string value is byte-for-byte
identical before and after (verified by tokenizing each file and
comparing the eval of every string literal). tthoma.py:1841 additionally
had a real '\\' (backslash) escape mixed in, so it becomes r'...' with
the doubled backslash reduced to one to keep the same value.
Files: rpcid.py, smi.py, tput.py, tthoma.py, ttmerge.py, ttsyslog.py.
Gate: `ruff check --select W605 util/` reports 32 findings before and 0
after. A standalone pytest scaffold (util/tests/test_trace_line.py,
table-driven) pins the trace-line regex behavior and asserts each fixed
file compiles with no SyntaxWarning under -W error; no new CI is wired.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug: invalid escape sequences in regex string literals (W605)
Several regex patterns in the
util/trace-analysis scripts are written as ordinary (non-raw) string literals but contain regex escapes like\[,\],\(,\),\+:Python treats
\[etc. as invalid escape sequences. Today they happen to evaluate to the intended backslash-plus-character, but each one emits aDeprecationWarning/SyntaxWarningand is scheduled to become a hard error in a future Python.ruffreports every one asW605.Fix
Convert the affected literals to raw strings:
Files touched:
rpcid.py,smi.py,tput.py,tthoma.py,ttmerge.py,ttsyslog.py.Every conversion is behavior-preserving. The evaluated string value is byte-for-byte identical before and after — verified by tokenizing each file and comparing
ast.literal_evalof every string literal (old tree vs new tree): all values identical. One line,tthoma.py:1841, also contained a genuine\\(backslash) escape mixed in with the invalid ones, so it becomesr'...'with the doubled backslash reduced to a single one, which keeps the exact same string value.Verification (linter gate + regression scaffold)
A standalone, table-driven pytest scaffold is included as executable documentation (no new CI is wired):
util/tests/test_trace_line.pypins the trace-line regex behavior (positive / boundary / negative / corner rows, each with adescriptionandexpected) and asserts every fixed source compiles with noSyntaxWarningunder warnings-as-errors — the pytest form of the W605 gate.