Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove node-specific logic from visit_default #4321

Merged
merged 1 commit into from
Apr 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions src/black/linegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,6 @@ def visit_default(self, node: LN) -> Iterator[Line]:

if any_open_brackets:
node.prefix = ""
if self.mode.string_normalization and node.type == token.STRING:
node.value = normalize_string_prefix(node.value)
node.value = normalize_string_quotes(node.value)
if node.type == token.NUMBER:
normalize_numeric_literal(node)
if node.type not in WHITESPACE:
self.current_line.append(node)
yield from super().visit_default(node)
Expand Down Expand Up @@ -420,12 +415,11 @@ def visit_STRING(self, leaf: Leaf) -> Iterator[Line]:
# indentation of those changes the AST representation of the code.
if self.mode.string_normalization:
docstring = normalize_string_prefix(leaf.value)
# visit_default() does handle string normalization for us, but
# since this method acts differently depending on quote style (ex.
# We handle string normalization at the end of this method, but since
# what we do right now acts differently depending on quote style (ex.
# see padding logic below), there's a possibility for unstable
# formatting as visit_default() is called *after*. To avoid a
# situation where this function formats a docstring differently on
# the second pass, normalize it early.
# formatting. To avoid a situation where this function formats a
# docstring differently on the second pass, normalize it early.
docstring = normalize_string_quotes(docstring)
else:
docstring = leaf.value
Expand Down Expand Up @@ -499,6 +493,13 @@ def visit_STRING(self, leaf: Leaf) -> Iterator[Line]:
else:
leaf.value = prefix + quote + docstring + quote

if self.mode.string_normalization and leaf.type == token.STRING:
leaf.value = normalize_string_prefix(leaf.value)
leaf.value = normalize_string_quotes(leaf.value)
yield from self.visit_default(leaf)

def visit_NUMBER(self, leaf: Leaf) -> Iterator[Line]:
normalize_numeric_literal(leaf)
yield from self.visit_default(leaf)

def __post_init__(self) -> None:
Expand Down
Loading