From 197885c71f1fee5bf3531edb6f175790ad3ed233 Mon Sep 17 00:00:00 2001 From: Zanie Date: Thu, 16 Nov 2023 08:55:03 -0600 Subject: [PATCH] Add failing test case for escaped curly braces bug in UP032 --- .../test/fixtures/pyupgrade/UP032_0.py | 17 ++++ ...__rules__pyupgrade__tests__UP032_0.py.snap | 88 +++++++++++++++++++ 2 files changed, 105 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 19868afac3284..c5f21e0b7d93d 100644 --- a/crates/ruff_linter/resources/test/fixtures/pyupgrade/UP032_0.py +++ b/crates/ruff_linter/resources/test/fixtures/pyupgrade/UP032_0.py @@ -226,3 +226,20 @@ async def c(): "".format(new_dict, d) ) + +# 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) + +("{}" "{{}}").format(a) + + +# Both strings will be converted to an f-string and the curly braces in the second should left escaped +( + "{}" + "{{{}}}" +).format(a, b) + +("{}" "{{{}}}").format(a, b) 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 4538fe9b917de..7cf99c42418d1 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 @@ -1066,5 +1066,93 @@ UP032_0.py:225:5: UP032 [*] Use f-string instead of `format` call 225 |+ f"Conflicting configuration dicts: {new_dict!r} {d!r}" 227 226 | 228 227 | ) +229 228 | + +UP032_0.py:231:1: UP032 [*] Use f-string instead of `format` call + | +230 | # The first string will be converted to an f-string and the curly braces in the second should be converted to be unescaped +231 | / ( +232 | | "{}" +233 | | "{{}}" +234 | | ).format(a) + | |___________^ UP032 +235 | +236 | ("{}" "{{}}").format(a) + | + = help: Convert to f-string + +ℹ Safe fix +229 229 | +230 230 | # The first string will be converted to an f-string and the curly braces in the second should be converted to be unescaped +231 231 | ( +232 |- "{}" + 232 |+ f"{a}" +233 233 | "{{}}" +234 |-).format(a) + 234 |+) +235 235 | +236 236 | ("{}" "{{}}").format(a) +237 237 | + +UP032_0.py:236:1: UP032 [*] Use f-string instead of `format` call + | +234 | ).format(a) +235 | +236 | ("{}" "{{}}").format(a) + | ^^^^^^^^^^^^^^^^^^^^^^^ UP032 + | + = help: Convert to f-string + +ℹ Safe fix +233 233 | "{{}}" +234 234 | ).format(a) +235 235 | +236 |-("{}" "{{}}").format(a) + 236 |+(f"{a}" "{{}}") +237 237 | +238 238 | +239 239 | # Both strings will be converted to an f-string and the curly braces in the second should left escaped + +UP032_0.py:240:1: UP032 [*] Use f-string instead of `format` call + | +239 | # Both strings will be converted to an f-string and the curly braces in the second should left escaped +240 | / ( +241 | | "{}" +242 | | "{{{}}}" +243 | | ).format(a, b) + | |______________^ UP032 +244 | +245 | ("{}" "{{{}}}").format(a, b) + | + = help: Convert to f-string + +ℹ Safe fix +238 238 | +239 239 | # Both strings will be converted to an f-string and the curly braces in the second should left escaped +240 240 | ( +241 |- "{}" +242 |- "{{{}}}" +243 |-).format(a, b) + 241 |+ f"{a}" + 242 |+ f"{{{b}}}" + 243 |+) +244 244 | +245 245 | ("{}" "{{{}}}").format(a, b) + +UP032_0.py:245:1: UP032 [*] Use f-string instead of `format` call + | +243 | ).format(a, b) +244 | +245 | ("{}" "{{{}}}").format(a, b) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP032 + | + = help: Convert to f-string + +ℹ Safe fix +242 242 | "{{{}}}" +243 243 | ).format(a, b) +244 244 | +245 |-("{}" "{{{}}}").format(a, b) + 245 |+(f"{a}" f"{{{b}}}")