@@ -635,16 +635,14 @@ def _formatArray(a, format_function, rank, max_line_len, next_line_prefix,
635
635
if rank == 0 :
636
636
return format_function (a [()]) + '\n '
637
637
638
- if summary_insert and 2 * edge_items < len (a ):
638
+ show_summary = summary_insert and 2 * edge_items < len (a )
639
+
640
+ if show_summary :
639
641
leading_items = edge_items
640
642
trailing_items = edge_items
641
- summary_insert1 = summary_insert + separator
642
- if legacy == '1.13' :
643
- summary_insert1 = summary_insert + ', '
644
643
else :
645
644
leading_items = 0
646
645
trailing_items = len (a )
647
- summary_insert1 = ""
648
646
649
647
if rank == 1 :
650
648
s = ""
@@ -653,9 +651,12 @@ def _formatArray(a, format_function, rank, max_line_len, next_line_prefix,
653
651
word = format_function (a [i ]) + separator
654
652
s , line = _extendLine (s , line , word , max_line_len , next_line_prefix )
655
653
656
- if summary_insert1 :
657
- s , line = _extendLine (s , line , summary_insert1 , max_line_len ,
658
- next_line_prefix )
654
+ if show_summary :
655
+ if legacy == '1.13' :
656
+ word = summary_insert + ", "
657
+ else :
658
+ word = summary_insert + separator
659
+ s , line = _extendLine (s , line , word , max_line_len , next_line_prefix )
659
660
660
661
for i in range (trailing_items , 1 , - 1 ):
661
662
word = format_function (a [- i ]) + separator
@@ -667,29 +668,29 @@ def _formatArray(a, format_function, rank, max_line_len, next_line_prefix,
667
668
s = '[' + s [len (next_line_prefix ):]
668
669
else :
669
670
s = '['
670
- sep = separator .rstrip ()
671
- line_sep = '\n ' * max (rank - 1 , 1 )
671
+ line_sep = separator .rstrip () + '\n ' * (rank - 1 )
672
672
for i in range (leading_items ):
673
673
if i > 0 :
674
674
s += next_line_prefix
675
675
s += _formatArray (a [i ], format_function , rank - 1 , max_line_len ,
676
676
" " + next_line_prefix , separator , edge_items ,
677
677
summary_insert , legacy )
678
- s = s .rstrip () + sep . rstrip () + line_sep
678
+ s = s .rstrip () + line_sep
679
679
680
- if summary_insert1 :
680
+ if show_summary :
681
681
if legacy == '1.13' :
682
- s += next_line_prefix + summary_insert1 + "\n "
682
+ # trailing space, fixed number of newlines, and fixed separator
683
+ s += next_line_prefix + summary_insert + ", \n "
683
684
else :
684
- s += next_line_prefix + summary_insert1 . strip () + line_sep
685
+ s += next_line_prefix + summary_insert + line_sep
685
686
686
687
for i in range (trailing_items , 1 , - 1 ):
687
688
if leading_items or i != trailing_items :
688
689
s += next_line_prefix
689
690
s += _formatArray (a [- i ], format_function , rank - 1 , max_line_len ,
690
691
" " + next_line_prefix , separator , edge_items ,
691
692
summary_insert , legacy )
692
- s = s .rstrip () + sep . rstrip () + line_sep
693
+ s = s .rstrip () + line_sep
693
694
if leading_items or trailing_items > 1 :
694
695
s += next_line_prefix
695
696
s += _formatArray (a [- 1 ], format_function , rank - 1 , max_line_len ,
0 commit comments