Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid fix for UP025 when implicitly concatenated with f-string #7784

Closed
dhruvmanila opened this issue Oct 3, 2023 · 3 comments · Fixed by #8709
Closed

Invalid fix for UP025 when implicitly concatenated with f-string #7784

dhruvmanila opened this issue Oct 3, 2023 · 3 comments · Fixed by #8709
Labels
bug Something isn't working fixes Related to suggested fixes for violations

Comments

@dhruvmanila
Copy link
Member

Note that this is unrelated to the new f-string changes.

If a unicode string is implicitly concatenated with a f-string, then the fix removes the first character of the string instead of the prefix:

u"foo" f"{bar}"

The fix:

$ pipx run "ruff==0.0.291" check --select=UP  ~/playground/ruff/fstring.py --ecosystem-ci
/Users/dhruv/playground/ruff/fstring.py:1:3: UP025 [*] Remove unicode literals from strings
ℹ Fix
1   |-u"foo" f"{bar}"
  1 |+u"oo" f"{bar}"

Found 1 error.
[*] 1 potentially fixable with the --fix option.

This is because the "foo" string is part of the outer f-string expression and the range of the string constant is within the quotes.

@dhruvmanila dhruvmanila added bug Something isn't working fixes Related to suggested fixes for violations labels Oct 3, 2023
@harupy
Copy link
Contributor

harupy commented Oct 10, 2023

@dhruvmanila Can I work on this?

@dhruvmanila
Copy link
Member Author

I would recommend to wait for this a bit as we could change the AST representation for an implicit string concatenation node which then would make this easier to solve.

@harupy
Copy link
Contributor

harupy commented Oct 10, 2023

@dhruvmanila Sounds good!

charliermarsh added a commit that referenced this issue Nov 16, 2023
## Summary

It seems like the range of an `ExprStringLiteral` can be somewhat
unreliable when the string is part of an implicit concatenation with an
f-string. Using the tokens themselves is more reliable.

Closes #8680.
Closes #7784.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixes Related to suggested fixes for violations
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants