fix(core): correct invalid string-literal escape sequences - #3116
Open
Bartok9 wants to merge 1 commit into
Open
Conversation
Several string literals used unrecognized backslash escapes (\_, \d, \], \ ) that Python flags with `SyntaxWarning: invalid escape sequence` and which become a hard SyntaxError in newer CPython, so a single offending literal can break module import. Doubled the backslashes (or marked an ASCII-art docstring raw) so the resulting string values are byte-for-byte identical while the warnings are gone.
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.
Summary
\_,\d,\],\).SyntaxWarning: invalid escape sequenceon Python 3.12+ and become a hardSyntaxErrorin newer CPython, where a single offending literal can prevent the whole module from importing.Root Cause
Symptom — Compiling these modules emits
SyntaxWarning: "\_" is an invalid escape sequence ...(and\d,\],\). On a CPython version that has promoted these to errors, importing the affected module fails outright.Root cause — In a normal (non-raw) Python string, a backslash followed by a character that is not a recognized escape (
\n,\t, ...) is a deprecated "invalid escape sequence." The affected literals were intended to contain a literal backslash:api_call.py:123—.replace("\_", "_")meant the two-character text\_.conn_vertica.py(3 sites) — SQLLIKE 'v\_%'(escaped underscore in a LIKE pattern).pdf.py(2 sites) — regex fragments\d,\/embedded in plain (non-r) strings.websearch_action.py:67— a\]inside a character class in a plain string concatenated onto anr"..."prefix.app_operator.py:172— ASCII-art (\in a diagram) inside a plain docstring.Evidence — Compiling each file on Python 3.14 with warnings enabled:
Fix + why this level — Escape the backslash explicitly (
\\_,\\d,\\],\\/) or mark the ASCII-art docstring raw (r"""). This is the correct layer: the literals already produced the right runtime value via the deprecated implicit behavior, so escaping at the literal makes the intent explicit and forward-compatible without changing any resulting string value. Suppressing the warning globally would have been the wrong level — it hides future breakage instead of removing the cause.Scope / risk — Touches only string-literal spelling in 5 files; the produced string values are byte-for-byte identical (verified below). No logic, control flow, or public API changes. The SQL
LIKE 'v\\_%'and the regex fragments evaluate to exactly the same patterns as before.Verification
Each edited literal was confirmed to evaluate to the identical string before and after:
After the fix, re-compiling all five files yields 0 invalid-escape warnings.
Real behavior proof
SyntaxWarning: invalid escape sequenceon 7 literals across 5 modules (hard error on newer CPython).upstream/main.packages/dbgpt-core/src/dbgpt/util/tests/test_no_invalid_escape.py— parametrized over the five files, asserts none emit an invalid-escapeSyntaxWarning. It FAILS without the fix and passes with it.