Skip to content

Commit

Permalink
fix string formatting with named escape adjacent to placeholder
Browse files Browse the repository at this point in the history
  • Loading branch information
asottile committed Sep 19, 2023
1 parent a61ea87 commit 5dd175d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pyupgrade/_string_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def parse_format(s: str) -> list[DotFormatPart]:

for part in NAMED_UNICODE_RE.split(s):
if NAMED_UNICODE_RE.fullmatch(part):
if not ret:
if not ret or ret[-1][1:] != (None, None, None):
ret.append((part, None, None, None))
else:
ret[-1] = (ret[-1][0] + part, None, None, None)
Expand Down
2 changes: 2 additions & 0 deletions tests/features/format_literals_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
'("{0}" # {1}\n"{2}").format(1, 2, 3)',
# don't touch f-strings (these are wrong but don't make it worse)
'f"{0}".format(a)',
# shouldn't touch the format spec
r'"{}\N{SNOWMAN}".format("")',
),
)
def test_format_literals_noop(s):
Expand Down

0 comments on commit 5dd175d

Please sign in to comment.