Simplify delimiter logic
This commit is contained in:
parent
b7f4ace0d1
commit
30d921f74c
29
black.py
29
black.py
@ -561,12 +561,13 @@ def mark(self, leaf: Leaf) -> None:
|
|||||||
leaf.opening_bracket = opening_bracket
|
leaf.opening_bracket = opening_bracket
|
||||||
leaf.bracket_depth = self.depth
|
leaf.bracket_depth = self.depth
|
||||||
if self.depth == 0:
|
if self.depth == 0:
|
||||||
after_delim = is_split_after_delimiter(leaf, self.previous)
|
delim = is_split_before_delimiter(leaf, self.previous)
|
||||||
before_delim = is_split_before_delimiter(leaf, self.previous)
|
if delim and self.previous is not None:
|
||||||
if after_delim > before_delim:
|
self.delimiters[id(self.previous)] = delim
|
||||||
self.delimiters[id(leaf)] = after_delim
|
else:
|
||||||
elif before_delim > after_delim and self.previous is not None:
|
delim = is_split_after_delimiter(leaf, self.previous)
|
||||||
self.delimiters[id(self.previous)] = before_delim
|
if delim:
|
||||||
|
self.delimiters[id(leaf)] = delim
|
||||||
if leaf.type in OPENING_BRACKETS:
|
if leaf.type in OPENING_BRACKETS:
|
||||||
self.bracket_match[self.depth, BRACKET[leaf.type]] = leaf
|
self.bracket_match[self.depth, BRACKET[leaf.type]] = leaf
|
||||||
self.depth += 1
|
self.depth += 1
|
||||||
@ -1438,13 +1439,6 @@ def is_split_after_delimiter(leaf: Leaf, previous: Leaf = None) -> int:
|
|||||||
if leaf.type == token.COMMA:
|
if leaf.type == token.COMMA:
|
||||||
return COMMA_PRIORITY
|
return COMMA_PRIORITY
|
||||||
|
|
||||||
if (
|
|
||||||
leaf.type in VARARGS
|
|
||||||
and leaf.parent
|
|
||||||
and leaf.parent.type in {syms.argument, syms.typedargslist}
|
|
||||||
):
|
|
||||||
return MATH_PRIORITY
|
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
@ -1456,6 +1450,15 @@ def is_split_before_delimiter(leaf: Leaf, previous: Leaf = None) -> int:
|
|||||||
|
|
||||||
Higher numbers are higher priority.
|
Higher numbers are higher priority.
|
||||||
"""
|
"""
|
||||||
|
if (
|
||||||
|
leaf.type in VARARGS
|
||||||
|
and leaf.parent
|
||||||
|
and leaf.parent.type in {syms.argument, syms.typedargslist}
|
||||||
|
):
|
||||||
|
# * and ** might also be MATH_OPERATORS but in this case they are not.
|
||||||
|
# Don't treat them as a delimiter.
|
||||||
|
return 0
|
||||||
|
|
||||||
if (
|
if (
|
||||||
leaf.type in MATH_OPERATORS
|
leaf.type in MATH_OPERATORS
|
||||||
and leaf.parent
|
and leaf.parent
|
||||||
|
Loading…
Reference in New Issue
Block a user