Fix SyntaxWarning invalid escape sequences in regex strings#197
Open
FranciscoPombal wants to merge 1 commit into
Open
Fix SyntaxWarning invalid escape sequences in regex strings#197FranciscoPombal wants to merge 1 commit into
SyntaxWarning invalid escape sequences in regex strings#197FranciscoPombal wants to merge 1 commit into
Conversation
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.
Problem
When running Ropper on modern Python versions (such as Python 3.12+ and the upcoming 3.14), the interpreter outputs multiple
SyntaxWarningmessages regarding invalid escape sequences:Python historically bypassed unescaped regular expressions like
\dor\[inside normal string literals by falling back to passing a literal backslash.In future Python versions, these warnings will be treated as hard
SyntaxErrorcompilation failures, breaking the application entirely.Solution
This PR resolves the deprecation warnings by explicitly specifying raw string literals using the
rprefix modifier for regex search patterns and constraint structures across the code.Using raw string definitions allows Python to preserve and pass literal backslashes to the underlying
reregular expression engine natively without processing them as Python-level string escape sequences first.Implementation details
This patch was generated entirely by running
ruff check . --select W605 --fixat the root of the repo.Testing/Verification
Run
PYTHONDONTWRITEBYTECODE=1 ropper --version.Compare the output with the expected results:
Before: Outputted noisy deprecation logs from python3.14/site-packages/ropper/*
After: Executes cleanly with no
SyntaxWarningwarnings thrown.