Skip to content

Commit

Permalink
Fix regular expression that black uses to identify f-expressions (#2287)
Browse files Browse the repository at this point in the history
Fixes #1469
  • Loading branch information
bbugyi200 committed May 30, 2021
1 parent 4ca4407 commit 199e3eb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
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

0 comments on commit 199e3eb

Please sign in to comment.