WiP: switch e.g. html/javascript template strings with embedded escape codes to raw string#395
Draft
jonasbardino wants to merge 8 commits into
Draft
Conversation
…scapes in them to raw strings in order to avoid DeprecationWarning (on python3.6+) or SyntaxError (python3.12+).
jonasbardino
force-pushed
the
fix/invalid-escape-sequences-in-strings-with-explicit-raw-strings
branch
from
July 17, 2026 12:34
0fcccff to
5d7a987
Compare
…rings to avoid DeprecationWarning or SyntaxError when running our code or the unit tests with recent python versions. Now `make unittest` completes without such issues. There may be additional cases lurking in parts of the code simply not covered by unittests yet.
…s are used. Now checking with `bandit -v -r mig/shared|grep 'invalid escape sequence'` only reports an invalid escaped '\S' in the ancient `forum.py` helper which is scheduled for retirement.
…s are used in `mig/server/` as well . Now checking with `bandit -v -r mig/|grep 'invalid escape sequence'` only reports an invalid escaped '\S' in the ancient `forum.py` helper which is scheduled for retirement. Reimplemented the dead-ugly conditional print in `print_on_error` in an attempt to prevent any future readers from going insane.
Contributor
Author
|
The final remaining lint error is a duplicate of the old one from #338. |
…eparate future branch. It is also necessary to introduce the now mandatory parenteses currently missing in the old (py2) print statements.
…leaving out the complex escaping to completely remove the need for r-strings there. Further updates may be needed there as well in the future task to fix the py2'isms like `print "bla"` without parentheses in the python version.
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.
Switch e.g. html/javascript template strings with embedded escapes in them to raw strings like
r"bla\*" in order to avoidDeprecationWarning(on python3.6+) orSyntaxError` (python3.12+).Tools like
banditwill warn about the existence of such strings when scanned so it can be used to locate all relevant occurrences in our code base.It's important to validate that the raw string wrapping does not change the meaning of the code. They typically remove the need for one level of escaping as in
Integrates #609 to prevent the corresponding old lint errors in existing code. So it's best to merge that one first.
Still pending some verification that none of the updates actually change the resulting strings. Manually verified for
server/*.pymodules so far.We should add unit tests to verify the correct output of the individual functions or the entire page.