Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix an f-string crash in ESP. #3463

Merged
merged 2 commits into from Dec 20, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.md
Expand Up @@ -19,6 +19,8 @@
- Fix a crash in preview style with assert + parenthesized string (#3415)
- Fix crashes in preview style with walrus operators used in function return annotations
and except clauses (#3423)
- Fix a crash in preview advanced string processing where mixed implicitly concatenated
regulard & f- strings start with an empty span (#3463)
JelleZijlstra marked this conversation as resolved.
Show resolved Hide resolved
- Do not put the closing quotes in a docstring on a separate line, even if the line is
too long (#3430)
- Long values in dict literals are now wrapped in parentheses; correspondingly
Expand Down
9 changes: 7 additions & 2 deletions src/black/trans.py
Expand Up @@ -1359,9 +1359,14 @@ def more_splits_should_be_made() -> bool:
# prefix, and the current custom split did NOT originally use a
# prefix...
if (
next_value != self._normalize_f_string(next_value, prefix)
and use_custom_breakpoints
use_custom_breakpoints
and not csplit.has_prefix
and (
# `next_value == prefix + QUOTE` happens when the custom
# split is an empty string.
next_value == prefix + QUOTE
or next_value != self._normalize_f_string(next_value, prefix)
)
):
# Then `csplit.break_idx` will be off by one after removing
# the 'f' prefix.
Expand Down
28 changes: 28 additions & 0 deletions tests/data/preview/long_strings__regression.py
Expand Up @@ -531,6 +531,18 @@ async def foo(self):
r"signiferumque, duo ea vocibus consetetur scriptorem. Facer \t",
}

# Regression test for https://github.com/psf/black/issues/3459.
xxxx(
empty_str_as_first_split=''
f'xxxxxxx {xxxxxxxxxx} xxx xxxxxxxxxx xxxxx xxx xxx xx '
'xxxxx xxxxxxxxx xxxxxxx, xxx xxxxxxxxxxx xxx xxxxx. '
f'xxxxxxxxxxxxx xxxx xx xxxxxxxxxx. xxxxx: {x.xxx}',
empty_u_str_as_first_split=u''
f'xxxxxxx {xxxxxxxxxx} xxx xxxxxxxxxx xxxxx xxx xxx xx '
'xxxxx xxxxxxxxx xxxxxxx, xxx xxxxxxxxxxx xxx xxxxx. '
f'xxxxxxxxxxxxx xxxx xx xxxxxxxxxx. xxxxx: {x.xxx}',
)


# output

Expand Down Expand Up @@ -1193,3 +1205,19 @@ async def foo(self):
r"signiferumque, duo ea vocibus consetetur scriptorem. Facer \t"
),
}

# Regression test for https://github.com/psf/black/issues/3459.
xxxx(
empty_str_as_first_split=(
""
f"xxxxxxx {xxxxxxxxxx} xxx xxxxxxxxxx xxxxx xxx xxx xx "
"xxxxx xxxxxxxxx xxxxxxx, xxx xxxxxxxxxxx xxx xxxxx. "
f"xxxxxxxxxxxxx xxxx xx xxxxxxxxxx. xxxxx: {x.xxx}"
),
empty_u_str_as_first_split=(
""
f"xxxxxxx {xxxxxxxxxx} xxx xxxxxxxxxx xxxxx xxx xxx xx "
"xxxxx xxxxxxxxx xxxxxxx, xxx xxxxxxxxxxx xxx xxxxx. "
f"xxxxxxxxxxxxx xxxx xx xxxxxxxxxx. xxxxx: {x.xxx}"
),
)