Skip to content

Commit

Permalink
Add failing test case for escaped curly braces bug in UP032
Browse files Browse the repository at this point in the history
  • Loading branch information
zanieb committed Nov 15, 2023
1 parent a783b14 commit 5d3e19b
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
14 changes: 14 additions & 0 deletions crates/ruff_linter/resources/test/fixtures/pyupgrade/UP032_0.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,3 +207,17 @@ async def c():
# The fixed string will exceed the line length, but it's still smaller than the
# existing line length, so it's fine.
"<Customer: {}, {}, {}, {}, {}>".format(self.internal_ids, self.external_ids, self.properties, self.tags, self.others)


# The first string will be converted to an f-string and the curly braces in the second should be converted to be unescaped
(
"{}"
"{{}}"
).format(a)


# Both strings will be converted to an f-string and the curly braces in the second should left escaped
(
"{}"
"{{{}}}"
).format(a, b)
Original file line number Diff line number Diff line change
Expand Up @@ -971,5 +971,54 @@ UP032_0.py:209:1: UP032 [*] Use f-string instead of `format` call
208 208 | # existing line length, so it's fine.
209 |-"<Customer: {}, {}, {}, {}, {}>".format(self.internal_ids, self.external_ids, self.properties, self.tags, self.others)
209 |+f"<Customer: {self.internal_ids}, {self.external_ids}, {self.properties}, {self.tags}, {self.others}>"
210 210 |
211 211 |
212 212 | # The first string will be converted to an f-string and the curly braces in the second should be converted to be unescaped

UP032_0.py:213:1: UP032 [*] Use f-string instead of `format` call
|
212 | # The first string will be converted to an f-string and the curly braces in the second should be converted to be unescaped
213 | / (
214 | | "{}"
215 | | "{{}}"
216 | | ).format(a)
| |___________^ UP032
|
= help: Convert to f-string

Safe fix
211 211 |
212 212 | # The first string will be converted to an f-string and the curly braces in the second should be converted to be unescaped
213 213 | (
214 |- "{}"
214 |+ f"{a}"
215 215 | "{{}}"
216 |-).format(a)
216 |+)
217 217 |
218 218 |
219 219 | # Both strings will be converted to an f-string and the curly braces in the second should left escaped

UP032_0.py:220:1: UP032 [*] Use f-string instead of `format` call
|
219 | # Both strings will be converted to an f-string and the curly braces in the second should left escaped
220 | / (
221 | | "{}"
222 | | "{{{}}}"
223 | | ).format(a, b)
| |______________^ UP032
|
= help: Convert to f-string

Safe fix
218 218 |
219 219 | # Both strings will be converted to an f-string and the curly braces in the second should left escaped
220 220 | (
221 |- "{}"
222 |- "{{{}}}"
223 |-).format(a, b)
221 |+ f"{a}"
222 |+ f"{{{b}}}"
223 |+)


0 comments on commit 5d3e19b

Please sign in to comment.