@@ -152,11 +152,6 @@ def visit_default(self, node: LN) -> Iterator[Line]:
152
152
153
153
if any_open_brackets :
154
154
node .prefix = ""
155
- if self .mode .string_normalization and node .type == token .STRING :
156
- node .value = normalize_string_prefix (node .value )
157
- node .value = normalize_string_quotes (node .value )
158
- if node .type == token .NUMBER :
159
- normalize_numeric_literal (node )
160
155
if node .type not in WHITESPACE :
161
156
self .current_line .append (node )
162
157
yield from super ().visit_default (node )
@@ -420,12 +415,11 @@ def visit_STRING(self, leaf: Leaf) -> Iterator[Line]:
420
415
# indentation of those changes the AST representation of the code.
421
416
if self .mode .string_normalization :
422
417
docstring = normalize_string_prefix (leaf .value )
423
- # visit_default() does handle string normalization for us , but
424
- # since this method acts differently depending on quote style (ex.
418
+ # We handle string normalization at the end of this method , but since
419
+ # what we do right now acts differently depending on quote style (ex.
425
420
# see padding logic below), there's a possibility for unstable
426
- # formatting as visit_default() is called *after*. To avoid a
427
- # situation where this function formats a docstring differently on
428
- # the second pass, normalize it early.
421
+ # formatting. To avoid a situation where this function formats a
422
+ # docstring differently on the second pass, normalize it early.
429
423
docstring = normalize_string_quotes (docstring )
430
424
else :
431
425
docstring = leaf .value
@@ -499,6 +493,13 @@ def visit_STRING(self, leaf: Leaf) -> Iterator[Line]:
499
493
else :
500
494
leaf .value = prefix + quote + docstring + quote
501
495
496
+ if self .mode .string_normalization and leaf .type == token .STRING :
497
+ leaf .value = normalize_string_prefix (leaf .value )
498
+ leaf .value = normalize_string_quotes (leaf .value )
499
+ yield from self .visit_default (leaf )
500
+
501
+ def visit_NUMBER (self , leaf : Leaf ) -> Iterator [Line ]:
502
+ normalize_numeric_literal (leaf )
502
503
yield from self .visit_default (leaf )
503
504
504
505
def __post_init__ (self ) -> None :
0 commit comments