Skip to content

Commit 7134754

Browse files
authored
Remove node-specific logic from visit_default (#4321)
This is the point of a visitor
1 parent 7669381 commit 7134754

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/black/linegen.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,6 @@ def visit_default(self, node: LN) -> Iterator[Line]:
152152

153153
if any_open_brackets:
154154
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)
160155
if node.type not in WHITESPACE:
161156
self.current_line.append(node)
162157
yield from super().visit_default(node)
@@ -420,12 +415,11 @@ def visit_STRING(self, leaf: Leaf) -> Iterator[Line]:
420415
# indentation of those changes the AST representation of the code.
421416
if self.mode.string_normalization:
422417
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.
425420
# 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.
429423
docstring = normalize_string_quotes(docstring)
430424
else:
431425
docstring = leaf.value
@@ -499,6 +493,13 @@ def visit_STRING(self, leaf: Leaf) -> Iterator[Line]:
499493
else:
500494
leaf.value = prefix + quote + docstring + quote
501495

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)
502503
yield from self.visit_default(leaf)
503504

504505
def __post_init__(self) -> None:

0 commit comments

Comments
 (0)