Repository navigation
fix: remove invalid escape sequences from Python sources - #22
Merged
Merged
Conversation
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.
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.
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 aSyntaxError. At that point the module fails to import, which takes down everytest 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_seriesdocstring puts a backslash before each backtick.
backend/tests/integration/test_sources_status_api.py:1- same pattern in themodule docstring.
pytestalready printsSyntaxWarning: invalid escape sequencefor these, sothe problem is visible but nothing fails.
What changed
gone. The rendered text is unchanged (
published_at,SCHEDULER_TIMEZONE,GET /api/gold/sources/status).backend/tests/unit/test_no_invalid_escape_sequences.pycompiles every.pyfile underbackend/and fails on anySyntaxWarning, reporting fileand line. A companion test asserts the scan really covers the tree (more than
100 files, including
app/main.pyandtests/conftest.py), so a wrong pathcannot make the guard pass vacuously.
Verification
Run from
backend/:python -m pytest tests/unit/test_no_invalid_escape_sequences.py-> 2 passedpython -m pytest-> 1231 passed, 2 failed; both failures are intests/unit/test_verify_setup.pyand come fromscripts/verify_setup.pyrejecting 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.
invalid escape sequencewarning no longer appears inpytestoutput.sync.pymakes the new guardfail; restoring the fix makes it pass.
Frontend untouched:
npm run lint,npm test(170 passed) andnpm run buildstill pass.
Risk
Low - no runtime behaviour changes, only docstrings plus a new unit test.