@@ -1733,47 +1733,33 @@ def draw_bbox(bbox, renderer, color='k', trans=None):
17331733 r .draw (renderer )
17341734
17351735
1736- def _pprint_table ( table , leadingspace = 2 ):
1736+ def _pprint_styles ( _styles ):
17371737 """
1738- Given the list of list of strings, return a string of REST table format.
1738+ A helper function for the _Style class. Given the dictionary of
1739+ {stylename: styleclass}, return a formatted string listing all the
1740+ styles. Used to update the documentation.
17391741 """
1742+ table = [('Class' , 'Name' , 'Attrs' ),
1743+ * [(cls .__name__ ,
1744+ # adding backquotes since - and | have special meaning in reST
1745+ f'``{ name } ``' ,
1746+ # [1:-1] drops the surrounding parentheses.
1747+ str (inspect .signature (cls ))[1 :- 1 ] or 'None' )
1748+ for name , cls in sorted (_styles .items ())]]
1749+ # Convert to rst table.
17401750 col_len = [max (len (cell ) for cell in column ) for column in zip (* table )]
1741- table_formatstr = ' ' .join ('=' * cl for cl in col_len )
1742- lines = [
1751+ table_formatstr = ' ' .join ('=' * cl for cl in col_len )
1752+ rst_table = ' \n ' . join ( [
17431753 '' ,
17441754 table_formatstr ,
1745- ' ' .join (cell .ljust (cl ) for cell , cl in zip (table [0 ], col_len )),
1755+ ' ' .join (cell .ljust (cl ) for cell , cl in zip (table [0 ], col_len )),
17461756 table_formatstr ,
1747- * [' ' .join (cell .ljust (cl ) for cell , cl in zip (row , col_len ))
1757+ * [' ' .join (cell .ljust (cl ) for cell , cl in zip (row , col_len ))
17481758 for row in table [1 :]],
17491759 table_formatstr ,
17501760 '' ,
1751- ]
1752- return textwrap .indent ('\n ' .join (lines ), ' ' * leadingspace )
1753-
1754-
1755- def _pprint_styles (_styles ):
1756- """
1757- A helper function for the _Style class. Given the dictionary of
1758- {stylename: styleclass}, return a formatted string listing all the
1759- styles. Used to update the documentation.
1760- """
1761- import inspect
1762-
1763- _table = [["Class" , "Name" , "Attrs" ]]
1764-
1765- for name , cls in sorted (_styles .items ()):
1766- spec = inspect .getfullargspec (cls .__init__ )
1767- if spec .defaults :
1768- argstr = ", " .join (map (
1769- "{}={}" .format , spec .args [- len (spec .defaults ):], spec .defaults
1770- ))
1771- else :
1772- argstr = 'None'
1773- # adding ``quotes`` since - and | have special meaning in reST
1774- _table .append ([cls .__name__ , "``%s``" % name , argstr ])
1775-
1776- return _pprint_table (_table )
1761+ ])
1762+ return textwrap .indent (rst_table , prefix = ' ' * 2 )
17771763
17781764
17791765def _simpleprint_styles (_styles ):
0 commit comments