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 regular expression that black uses to identify f-expressions #2287

Merged
merged 4 commits into from May 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions CHANGES.md
Expand Up @@ -12,6 +12,7 @@
- Add extra uvloop install + import support if in python env (#2258)
- Fix --experimental-string-processing crash when matching parens are not found (#2283)
- Make sure to split lines that start with a string operator (#2286)
- Fix regular expression that black uses to identify f-expressions (#2287)

### _Blackd_

Expand Down
4 changes: 2 additions & 2 deletions src/black/trans.py
Expand Up @@ -971,8 +971,8 @@ class StringSplitter(CustomSplitMapMixin, BaseStringSplitter):
| \{\{
| \}\}
| (?R)
)+?
(?<!\}) \} (?:\}\})* (?!\})
)+
\}
"""

def do_splitter_match(self, line: Line) -> TMatchResult:
Expand Down
12 changes: 12 additions & 0 deletions tests/data/long_strings__regression.py
Expand Up @@ -407,6 +407,12 @@ def _legacy_listen_examples():
)


temp_msg = (
f"{f'{humanize_number(pos)}.': <{pound_len+2}} "
f"{balance: <{bal_len + 5}} "
f"<<{author.display_name}>>\n"
)

assert str(suffix_arr) == (
"['$', 'angaroo$', 'angrykangaroo$', 'aroo$', 'garoo$', "
"'grykangaroo$', 'kangaroo$', 'ngaroo$', 'ngrykangaroo$', "
Expand Down Expand Up @@ -942,6 +948,12 @@ def _legacy_listen_examples():
)


temp_msg = (
f"{f'{humanize_number(pos)}.': <{pound_len+2}} "
f"{balance: <{bal_len + 5}} "
f"<<{author.display_name}>>\n"
)

assert (
str(suffix_arr)
== "['$', 'angaroo$', 'angrykangaroo$', 'aroo$', 'garoo$', "
Expand Down