Repository navigation
Use raw strings for regular expressions - #2897
Open
tompollard wants to merge 1 commit into
Open
tompollard wants to merge 1 commit into
tompollard wants to merge 1 commit into
Conversation
Regexes like '\w' and '\s' in normal strings are invalid escape sequences. Python 3.12 shows a SyntaxWarning for them on every startup, and a future version will make them errors. Raw strings give the same patterns without the warning.
This branch has not been deployed
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.
Several regexes were written as normal strings, so sequences like
\w,\sand\-were invalid string escapes. They still worked because Python passes unknown escapes through unchanged, but Python 3.12 shows aSyntaxWarningfor each one every time the code is loaded (they appear at the top of the CI logs), and a future Python version will make them errors.This adds an
rprefix to the 11 affected strings:lightwave/views.py: the CGI header regexsearch/urls.py: sixre_pathpatterns for published project content and legacy redirectsuser/test_integration.pyanduser/test_views.py: the email verification link regex in four testsThe resulting strings are identical, so the patterns don't change. I checked this by comparing every string constant in the four files before and after. One line in
user/test_views.pyis rewrapped to stay within the line length limit.Testing
SyntaxWarnings from any tracked Python file.manage.py checkpasses with-W error::SyntaxWarning.