Repository navigation
Conversation
The textual occurrence pattern matched `\bname\b`, so for a variable
called `f` it also matched the `f` of an f-string prefix (and likewise
`b`, `u`, `rf`, ...). Rename rewrote `f"{f}"` into `g"{g}"` and inline
produced `1"{1}"`, both syntax errors.
A name directly followed by a quote can only be a string prefix, so
skip those matches and let the string patterns consume the literal.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
aliassar
force-pushed
the
fix-rename-string-prefix
branch
from
November 10, 2026 21:12
7dd4b6d to
22a54c2
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #949 +/- ##
=======================================
Coverage 95.43% 95.43%
=======================================
Files 134 134
Lines 26843 26853 +10
=======================================
+ Hits 25618 25628 +10
Misses 1225 1225 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Description
The occurrence regex in
_TextualFindermatched\bname\b, so renaming a variable calledfalso hit thefof everyf"..."prefix (same forb,u,rf, ...) and produced code likefh.write(fh"{r}"). In valid Python a name directly followed by a quote can only be a string prefix, so the pattern now has a(?!["'])lookahead. Names inside the replacement fields are still renamed.docs=Trueuses a plain substring search with the same problem; I left it alone because there a quoted'f'in a docstring is a real match. #906 would also fix this as part of its move to the tokenizer (I checked and it gives the same output on these cases), so if that lands first I can drop the code change and keep just the tests.Two new tests in
renametest.pyfail on master and pass now. The full suite on 3.13 gives 2170 passed, 7 skipped, 5 xfailed; the one error,test_get_package_tuple_compiled, also happens on master.Fixes #948
Checklist (delete if not relevant):