File tree 3 files changed +18
-6
lines changed
3 files changed +18
-6
lines changed Original file line number Diff line number Diff line change 39
39
40
40
- Fix bug with Black incorrectly parsing empty lines with a backslash (#4343 )
41
41
42
+ - Fix bugs with Black's tokenizer not handling ` \{ ` inside f-strings very well (#4422 )
43
+
42
44
- Fix incorrect line numbers in the tokenizer for certain tokens within f-strings
43
45
(#4423 )
44
46
Original file line number Diff line number Diff line change @@ -136,12 +136,12 @@ def _combinations(*l: str) -> Set[str]:
136
136
)
137
137
138
138
# 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)({) (?!{)'
141
141
142
142
# 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){(?!{)'
145
145
146
146
# ! format specifier inside an fstring brace, ensure it's not a `!=` token
147
147
Bang = Whitespace + group ("!" ) + r"(?!=)"
@@ -175,8 +175,8 @@ def _combinations(*l: str) -> Set[str]:
175
175
_string_middle_double = r'(?:[^\n"\\]|\\.)*'
176
176
177
177
# 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
180
180
181
181
# First (or only) line of ' or " string.
182
182
ContStr = group (
Original file line number Diff line number Diff line change 131
131
f"{ '\' ' } "
132
132
f"{ f'\' ' } "
133
133
134
+ f'{ 1 } \{{'
135
+ f'{ 2 } foo \{{[\}}'
136
+ f'\{ 3 } '
137
+ rf"\{ "a" } "
138
+
134
139
# output
135
140
136
141
x = f"foo"
264
269
265
270
f"{ '\' ' } "
266
271
f"{ 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