File tree Expand file tree Collapse file tree 3 files changed +18
-6
lines changed
Expand file tree Collapse file tree 3 files changed +18
-6
lines changed Original file line number Diff line number Diff line change 3939
4040- Fix bug with Black incorrectly parsing empty lines with a backslash (#4343 )
4141
42+ - Fix bugs with Black's tokenizer not handling ` \{ ` inside f-strings very well (#4422 )
43+
4244- Fix incorrect line numbers in the tokenizer for certain tokens within f-strings
4345 (#4423 )
4446
Original file line number Diff line number Diff line change @@ -136,12 +136,12 @@ def _combinations(*l: str) -> Set[str]:
136136)
137137
138138# beginning of a single quoted f-string. must not end with `{{` or `\N{`
139- SingleLbrace = r"(?:\\N{|\\.| {{|[^'\\ {])*(?<!\\N){ (?!{)"
140- DoubleLbrace = r'(?:\\N{|\\.| {{|[^"\\ {])*(?<!\\N){ (?!{)'
139+ SingleLbrace = r"(?:\\N{|{{|\\'|[^\n' {])*(?<!\\N)({) (?!{)"
140+ DoubleLbrace = r'(?:\\N{|{{|\\"|[^\n" {])*(?<!\\N)({) (?!{)'
141141
142142# beginning of a triple quoted f-string. must not end with `{{` or `\N{`
143- Single3Lbrace = r"(?:\\N{|\\[^{]|{{|' (?!'')|[^'{\\ ])*(?<!\\N){(?!{)"
144- Double3Lbrace = r'(?:\\N{|\\[^{]|{{|" (?!"")|[^"{\\ ])*(?<!\\N){(?!{)'
143+ Single3Lbrace = r"(?:\\N{|{{|\\'|' (?!'')|[^'{])*(?<!\\N){(?!{)"
144+ Double3Lbrace = r'(?:\\N{|{{|\\"|" (?!"")|[^"{])*(?<!\\N){(?!{)'
145145
146146# ! format specifier inside an fstring brace, ensure it's not a `!=` token
147147Bang = Whitespace + group ("!" ) + r"(?!=)"
@@ -175,8 +175,8 @@ def _combinations(*l: str) -> Set[str]:
175175_string_middle_double = r'(?:[^\n"\\]|\\.)*'
176176
177177# FSTRING_MIDDLE and LBRACE, must not end with a `{{` or `\N{`
178- _fstring_middle_single = r"(?:\\N{|\\[^{]|{{|[^\n'{\\])*(?<!\\N)({)(?!{)"
179- _fstring_middle_double = r'(?:\\N{|\\[^{]|{{|[^\n"{\\])*(?<!\\N)({)(?!{)'
178+ _fstring_middle_single = SingleLbrace
179+ _fstring_middle_double = DoubleLbrace
180180
181181# First (or only) line of ' or " string.
182182ContStr = group (
Original file line number Diff line number Diff line change 131131f"{ '\' ' } "
132132f"{ f'\' ' } "
133133
134+ f'{ 1 } \{{'
135+ f'{ 2 } foo \{{[\}}'
136+ f'\{ 3 } '
137+ rf"\{ "a" } "
138+
134139# output
135140
136141x = f"foo"
264269
265270f"{ '\' ' } "
266271f"{ f'\' ' } "
272+
273+ f"{ 1 } \{{"
274+ f"{ 2 } foo \{{[\}}"
275+ f"\{ 3 } "
276+ rf"\{ "a" } "
You can’t perform that action at this time.
0 commit comments