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

PIE810 autofix changes raw strings to backslashes #9663

Closed
JelleZijlstra opened this issue Jan 28, 2024 · 1 comment · Fixed by #15694
Closed

PIE810 autofix changes raw strings to backslashes #9663

JelleZijlstra opened this issue Jan 28, 2024 · 1 comment · Fixed by #15694
Assignees
Labels
bug Something isn't working fixes Related to suggested fixes for violations

Comments

@JelleZijlstra
Copy link
Contributor

JelleZijlstra commented Jan 28, 2024

Start with this code:

if x.startswith("a") or x.startswith("b") or re.match(r"a\.b", x):
    pass

Ruff correctly complains that I should use a single .startswith() call.

Run Ruff's autofix for PIE810:

if x.startswith(("a", "b")) or re.match("a\\.b", x):
    pass

And now my string is not raw any more.

@charliermarsh
Copy link
Member

👍 This is a specific instance of a general problem (#7799), though we may want to fix this case specifically since it's common for this to contain strings.

@charliermarsh charliermarsh added bug Something isn't working fixes Related to suggested fixes for violations labels Jan 28, 2024
@ntBre ntBre self-assigned this Jan 23, 2025
ntBre added a commit that referenced this issue Jan 23, 2025
## Summary

Fixes #9663 and also improves the fixes for
[RUF055](https://docs.astral.sh/ruff/rules/unnecessary-regular-expression/)
since regular expressions are often written as raw strings.

This doesn't include raw f-strings.

## Test Plan

Existing snapshots for RUF055 and PT009, plus a new `Generator` test and
a regression test for the reported `PIE810` issue.
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.

3 participants