From 5d3e19b72a4dcf1bf6a087574aff55c4ccc96715 Mon Sep 17 00:00:00 2001 From: Zanie Date: Wed, 15 Nov 2023 10:01:13 -0600 Subject: [PATCH] Add failing test case for escaped curly braces bug in UP032 --- .../test/fixtures/pyupgrade/UP032_0.py | 14 ++++++ ...__rules__pyupgrade__tests__UP032_0.py.snap | 49 +++++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/crates/ruff_linter/resources/test/fixtures/pyupgrade/UP032_0.py b/crates/ruff_linter/resources/test/fixtures/pyupgrade/UP032_0.py index 0ba30683b92ae..6e8b7e8c728de 100644 --- a/crates/ruff_linter/resources/test/fixtures/pyupgrade/UP032_0.py +++ b/crates/ruff_linter/resources/test/fixtures/pyupgrade/UP032_0.py @@ -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. "".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) \ No newline at end of file diff --git a/crates/ruff_linter/src/rules/pyupgrade/snapshots/ruff_linter__rules__pyupgrade__tests__UP032_0.py.snap b/crates/ruff_linter/src/rules/pyupgrade/snapshots/ruff_linter__rules__pyupgrade__tests__UP032_0.py.snap index b6849b082c216..c38645660ba75 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/snapshots/ruff_linter__rules__pyupgrade__tests__UP032_0.py.snap +++ b/crates/ruff_linter/src/rules/pyupgrade/snapshots/ruff_linter__rules__pyupgrade__tests__UP032_0.py.snap @@ -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 |-"".format(self.internal_ids, self.external_ids, self.properties, self.tags, self.others) 209 |+f"" +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 |+)