@@ -864,6 +864,10 @@ def is_line_short_enough(line: Line, *, mode: Mode, line_str: str = "") -> bool:
864864 for i , leaf in enumerate (line .leaves ):
865865 if max_level_to_update == math .inf :
866866 had_comma : int | None = None
867+ # Skip multiline_string_handling logic for leaves without bracket_depth
868+ # (e.g., newly created leaves not yet processed by bracket tracker)
869+ if not hasattr (leaf , "bracket_depth" ):
870+ continue
867871 if leaf .bracket_depth + 1 > len (commas ):
868872 commas .append (0 )
869873 elif leaf .bracket_depth + 1 < len (commas ):
@@ -879,17 +883,22 @@ def is_line_short_enough(line: Line, *, mode: Mode, line_str: str = "") -> bool:
879883 # MLS was in parens with at least one comma - force split
880884 return False
881885
882- if leaf .bracket_depth <= max_level_to_update and leaf .type == token .COMMA :
883- # Inside brackets, ignore trailing comma
884- # directly after MLS/MLS-containing expression
885- ignore_ctxs : list [LN | None ] = [None ]
886- ignore_ctxs += multiline_string_contexts
887- if (line .inside_brackets or leaf .bracket_depth > 0 ) and (
888- i != len (line .leaves ) - 1 or leaf .prev_sibling not in ignore_ctxs
889- ):
890- commas [leaf .bracket_depth ] += 1
891- if max_level_to_update != math .inf :
892- max_level_to_update = min (max_level_to_update , leaf .bracket_depth )
886+ # Skip bracket-depth-dependent processing for leaves without the attribute
887+ if not hasattr (leaf , "bracket_depth" ):
888+ # Still process multiline string detection below
889+ pass
890+ else :
891+ if leaf .bracket_depth <= max_level_to_update and leaf .type == token .COMMA :
892+ # Inside brackets, ignore trailing comma
893+ # directly after MLS/MLS-containing expression
894+ ignore_ctxs : list [LN | None ] = [None ]
895+ ignore_ctxs += multiline_string_contexts
896+ if (line .inside_brackets or leaf .bracket_depth > 0 ) and (
897+ i != len (line .leaves ) - 1 or leaf .prev_sibling not in ignore_ctxs
898+ ):
899+ commas [leaf .bracket_depth ] += 1
900+ if max_level_to_update != math .inf :
901+ max_level_to_update = min (max_level_to_update , leaf .bracket_depth )
893902
894903 if is_multiline_string (leaf ):
895904 if leaf .parent and (
0 commit comments