From 8009888479e3c9834d12c15ce7c6f37ad13c34c8 Mon Sep 17 00:00:00 2001 From: Booomeii <604772159@qq.com> Date: Sun, 14 Jan 2024 22:41:02 +0800 Subject: [PATCH] Fix ci --- src/black/linegen.py | 4 ++-- src/black/lines.py | 33 +++++++++++++++++++++------------ 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/src/black/linegen.py b/src/black/linegen.py index 49dcaf1d0ef..c5d882bdd7c 100644 --- a/src/black/linegen.py +++ b/src/black/linegen.py @@ -911,7 +911,7 @@ def _maybe_split_omitting_optional_parens( and not line.is_import # and we can actually remove the parens and can_omit_invisible_parens(rhs, mode.line_length) - and (Preview.improve_call_chain not in mode or not rhs.body.is_call_chain) + and not (Preview.improve_call_chain in mode and rhs.body.is_call_chain) ): omit = {id(rhs.closing_bracket), *omit} try: @@ -1182,7 +1182,7 @@ def delimiter_split( raise CannotSplit("No delimiters found") from None if ( - Preview.improve_call_chain not in mode + not (Preview.improve_call_chain in mode and line.is_call_chain) and delimiter_priority == DOT_PRIORITY and bt.delimiter_count_with_priority(delimiter_priority) == 1 ): diff --git a/src/black/lines.py b/src/black/lines.py index fde23893095..41e1424f278 100644 --- a/src/black/lines.py +++ b/src/black/lines.py @@ -225,19 +225,28 @@ def is_call_chain(self) -> bool: """Is the line a call chain""" if self.comments: return False - count = 0 line_node = self.leaves[0].parent - if line_node: - for child in line_node.children: - if ( - child.type == syms.trailer - and child.children[0].type == token.DOT - and child.next_sibling - and child.next_sibling.type == syms.trailer - and child.next_sibling.children[0].type in OPENING_BRACKETS - ): - count += 1 - return count > 1 + if not line_node: + return False + depth = 2 if line_node.type == syms.old_comp_for else 1 + + def get_call_count(node: Node, depth: int) -> int: + count = 0 + for child in node.children: + if isinstance(child, Node): + if ( + child.type == syms.trailer + and child.children[0].type == token.DOT + and child.next_sibling + and child.next_sibling.type == syms.trailer + and child.next_sibling.children[0].type in OPENING_BRACKETS + ): + count += 1 + elif depth - 1 > 0: + count += get_call_count(child, depth - 1) + return count + + return get_call_count(line_node, depth) > 1 @property def opens_block(self) -> bool: