Skip to content

fix: remove invalid escape sequences from Python sources - #22

Merged
JasonBuildAI merged 1 commit into
mainfrom
fix/invalid-escape-sequences
Nov 24, 2026
Merged

JasonBuildAI merged 1 commit into
mainfrom
fix/invalid-escape-sequences

Conversation

@JasonBuildAI

Copy link
Copy Markdown
Owner

Why

Python 3.12 turns invalid escape sequences inside string literals into a
SyntaxWarning, and the language's direction of travel is to make them a
SyntaxError. At that point the module fails to import, which takes down every
test and every request that touches it.

Two Python sources in this repo still carry such a sequence:

  • backend/app/services/quant/sync.py:343 - the _digest_count_series
    docstring puts a backslash before each backtick.
  • backend/tests/integration/test_sources_status_api.py:1 - same pattern in the
    module docstring.

pytest already prints SyntaxWarning: invalid escape sequence for these, so
the problem is visible but nothing fails.

What changed

  • Both docstrings are raw strings; the backslashes before the backticks are
    gone. The rendered text is unchanged (published_at,
    SCHEDULER_TIMEZONE, GET /api/gold/sources/status).
  • New backend/tests/unit/test_no_invalid_escape_sequences.py compiles every
    .py file under backend/ and fails on any SyntaxWarning, reporting file
    and line. A companion test asserts the scan really covers the tree (more than
    100 files, including app/main.py and tests/conftest.py), so a wrong path
    cannot make the guard pass vacuously.

Verification

Run from backend/:

  • python -m pytest tests/unit/test_no_invalid_escape_sequences.py -> 2 passed
  • python -m pytest -> 1231 passed, 2 failed; both failures are in
    tests/unit/test_verify_setup.py and come from scripts/verify_setup.py
    rejecting this machine's Python 3.13 interpreter (it accepts 3.11/3.12 only).
    CI runs 3.11, where they pass; this PR does not touch that check.
  • The invalid escape sequence warning no longer appears in pytest output.
  • Mutation check: reintroducing the backslash in sync.py makes the new guard
    fail; restoring the fix makes it pass.

Frontend untouched: npm run lint, npm test (170 passed) and npm run build
still pass.

Risk

Low - no runtime behaviour changes, only docstrings plus a new unit test.

Python 3.12+ emits a SyntaxWarning for invalid escape sequences, and
future versions turn it into a SyntaxError that breaks the import of the
whole module. Two docstrings escaped backticks with a backslash - in
app/services/quant/sync.py and
tests/integration/test_sources_status_api.py. Both are raw strings now
and the stray backslashes are gone.

The new tests/unit/test_no_invalid_escape_sequences.py compiles every
Python file under backend/ and fails on any SyntaxWarning, plus a
companion check that the scan really covers the tree so a wrong path
cannot pass silently.
@JasonBuildAI
JasonBuildAI merged commit 9a324c6 into main Nov 24, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant