File tree Expand file tree Collapse file tree 3 files changed +13
-3
lines changed Expand file tree Collapse file tree 3 files changed +13
-3
lines changed Original file line number Diff line number Diff line change 19
19
under some circumstances. (#3745 )
20
20
- Fix a bug where multi-line open parenthesis magic comment like ` type: ignore ` were not
21
21
correctly parsed (#3740 )
22
+ - Fix error in AST validation when Black removes trailing whitespace in a type comment
23
+ (#3773 )
22
24
23
25
### Preview style
24
26
Original file line number Diff line number Diff line change @@ -208,15 +208,18 @@ def stringify_ast(node: ast.AST, depth: int = 0) -> Iterator[str]:
208
208
209
209
else :
210
210
normalized : object
211
- # Constant strings may be indented across newlines, if they are
212
- # docstrings; fold spaces after newlines when comparing. Similarly,
213
- # trailing and leading space may be removed.
214
211
if (
215
212
isinstance (node , ast .Constant )
216
213
and field == "value"
217
214
and isinstance (value , str )
218
215
):
216
+ # Constant strings may be indented across newlines, if they are
217
+ # docstrings; fold spaces after newlines when comparing. Similarly,
218
+ # trailing and leading space may be removed.
219
219
normalized = _normalize ("\n " , value )
220
+ elif field == "type_comment" and isinstance (value , str ):
221
+ # Trailing whitespace in type comments is removed.
222
+ normalized = value .rstrip ()
220
223
else :
221
224
normalized = value
222
225
yield f"{ ' ' * (depth + 2 )} { normalized !r} , # { value .__class__ .__name__ } "
Original file line number Diff line number Diff line change @@ -154,6 +154,9 @@ def _init_host(self, parsed) -> None:
154
154
not parsed .hostname .strip ()):
155
155
pass
156
156
157
+
158
+ a = "type comment with trailing space" # type: str
159
+
157
160
#######################
158
161
### SECTION COMMENT ###
159
162
#######################
@@ -332,6 +335,8 @@ def _init_host(self, parsed) -> None:
332
335
pass
333
336
334
337
338
+ a = "type comment with trailing space" # type: str
339
+
335
340
#######################
336
341
### SECTION COMMENT ###
337
342
#######################
You can’t perform that action at this time.
0 commit comments