Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 180920e

Browse files
committed
Replace inspect.getfullargspec by inspect.signature.
... and inline _pprint_table into _pprint_styles -- they're short enough.
1 parent 2cc5d8d commit 180920e

File tree

2 files changed

+23
-43
lines changed

2 files changed

+23
-43
lines changed

lib/matplotlib/artist.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,18 +1308,12 @@ def _get_setters_and_targets(self):
13081308
if not name.startswith('set_'):
13091309
continue
13101310
func = getattr(self.o, name)
1311-
if not callable(func):
1311+
if (not callable(func)
1312+
or len(inspect.signature(func).parameters) < 2
1313+
or self.is_alias(func)):
13121314
continue
1313-
nargs = len(inspect.getfullargspec(func).args)
1314-
if nargs < 2 or self.is_alias(func):
1315-
continue
1316-
source_class = self.o.__module__ + "." + self.o.__name__
1317-
for cls in self.o.mro():
1318-
if name in cls.__dict__:
1319-
source_class = cls.__module__ + "." + cls.__name__
1320-
break
1321-
source_class = self._replace_path(source_class)
1322-
setters.append((name[4:], source_class + "." + name))
1315+
setters.append(
1316+
(name[4:], f"{func.__module__}.{func.__qualname__}"))
13231317
return setters
13241318

13251319
def _replace_path(self, source_class):

lib/matplotlib/patches.py

Lines changed: 18 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -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

17791765
def _simpleprint_styles(_styles):

0 commit comments

Comments
 (0)