You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## 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.
Copy file name to clipboardexpand all lines: crates/ruff_linter/src/rules/flake8_pie/snapshots/ruff_linter__rules__flake8_pie__tests__PIE810_PIE810.py.snap
+18
Original file line number
Diff line number
Diff line change
@@ -142,3 +142,21 @@ PIE810.py:25:8: PIE810 [*] Call `startswith` once with a `tuple`
Copy file name to clipboardexpand all lines: crates/ruff_linter/src/rules/flake8_pytest_style/snapshots/ruff_linter__rules__flake8_pytest_style__tests__PT009.snap
+4-4
Original file line number
Diff line number
Diff line change
@@ -498,7 +498,7 @@ PT009.py:73:9: PT009 [*] Use a regular `assert` instead of unittest-style `asser
498
498
7171|
499
499
7272|deftest_assert_regex(self):
500
500
73|-self.assertRegex("abc", r"def") # Error
501
-
73|+assertre.search("def", "abc") # Error
501
+
73|+assertre.search(r"def", "abc") # Error
502
502
7474|
503
503
7575|deftest_assert_not_regex(self):
504
504
7676|self.assertNotRegex("abc", r"abc") # Error
@@ -518,7 +518,7 @@ PT009.py:76:9: PT009 [*] Use a regular `assert` instead of unittest-style `asser
Copy file name to clipboardexpand all lines: crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF055_RUF055_0.py.snap
+8-8
Original file line number
Diff line number
Diff line change
@@ -142,14 +142,14 @@ RUF055_0.py:89:1: RUF055 [*] Plain string pattern passed to `re` function
142
142
90 | re.sub(r"a", r"\n", "a")
143
143
91 | re.sub(r"a", "\a", "a")
144
144
|
145
-
= help: Replace with `"a".replace("a", "\n")`
145
+
= help: Replace with `"a".replace(r"a", "\n")`
146
146
147
147
ℹ Safe fix
148
148
86 86 | # `re.sub(r"a", r"\n", some_string)` is fixed to `some_string.replace("a", "\n")`
Copy file name to clipboardexpand all lines: crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF055_RUF055_1.py.snap
+2-2
Original file line number
Diff line number
Diff line change
@@ -29,11 +29,11 @@ RUF055_1.py:17:1: RUF055 [*] Plain string pattern passed to `re` function
29
29
17 | re.sub(r"abc", repl, haystack)
30
30
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ RUF055
31
31
|
32
-
= help: Replace with `haystack.replace("abc", repl)`
32
+
= help: Replace with `haystack.replace(r"abc", repl)`
33
33
34
34
ℹ Safe fix
35
35
14 14 |
36
36
15 15 | # also works for the `repl` argument in sub
0 commit comments