@@ -96,23 +96,20 @@ def __auto_column_widths(self) -> List[int]:
9696 The minimum number of characters needed for each column
9797 """
9898
99- def widest_line (text : str ) -> int :
99+ def widest_line (value : SupportsStr ) -> int :
100100 """Returns the width of the longest line in a multi-line string"""
101+ text = str (value )
101102 return max (len (line ) for line in text .splitlines ()) if len (text ) else 0
102103
103104 column_widths = []
104105 # get the width necessary for each column
105106 for i in range (self .__columns ):
106- # col_widest returns the width of the widest line in the ith cell of a given list
107- col_widest : Callable [[List [SupportsStr ], int ], int ] = lambda row , i = i : widest_line (
108- str (row [i ])
109- )
110107 # number of characters in column of i of header, each body row, and footer
111- header_size = col_widest (self .__header ) if self .__header else 0
112- body_size = map ( col_widest , self .__body ) if self .__body else [ 0 ]
113- footer_size = col_widest (self .__footer ) if self .__footer else 0
108+ header_size = widest_line (self .__header [ i ] ) if self .__header else 0
109+ body_size = max ( widest_line ( row [ i ]) for row in self .__body ) if self .__body else 0
110+ footer_size = widest_line (self .__footer [ i ] ) if self .__footer else 0
114111 # get the max and add 2 for padding each side with a space
115- column_widths .append (max (header_size , * body_size , footer_size ) + 2 )
112+ column_widths .append (max (header_size , body_size , footer_size ) + 2 )
116113 return column_widths
117114
118115 def __pad (self , cell_value : SupportsStr , width : int , alignment : Alignment ) -> str :
0 commit comments