diff --git a/lib/matplotlib/artist.py b/lib/matplotlib/artist.py index aa1e2e376350..6ce0b5eed413 100644 --- a/lib/matplotlib/artist.py +++ b/lib/matplotlib/artist.py @@ -1308,18 +1308,12 @@ def _get_setters_and_targets(self): if not name.startswith('set_'): continue func = getattr(self.o, name) - if not callable(func): + if (not callable(func) + or len(inspect.signature(func).parameters) < 2 + or self.is_alias(func)): continue - nargs = len(inspect.getfullargspec(func).args) - if nargs < 2 or self.is_alias(func): - continue - source_class = self.o.__module__ + "." + self.o.__name__ - for cls in self.o.mro(): - if name in cls.__dict__: - source_class = cls.__module__ + "." + cls.__name__ - break - source_class = self._replace_path(source_class) - setters.append((name[4:], source_class + "." + name)) + setters.append( + (name[4:], f"{func.__module__}.{func.__qualname__}")) return setters def _replace_path(self, source_class): diff --git a/lib/matplotlib/patches.py b/lib/matplotlib/patches.py index 995c9242fdf2..da89c6a0ae95 100644 --- a/lib/matplotlib/patches.py +++ b/lib/matplotlib/patches.py @@ -1733,47 +1733,33 @@ def draw_bbox(bbox, renderer, color='k', trans=None): r.draw(renderer) -def _pprint_table(table, leadingspace=2): +def _pprint_styles(_styles): """ - Given the list of list of strings, return a string of REST table format. + A helper function for the _Style class. Given the dictionary of + {stylename: styleclass}, return a formatted string listing all the + styles. Used to update the documentation. """ + table = [('Class', 'Name', 'Attrs'), + *[(cls.__name__, + # adding backquotes since - and | have special meaning in reST + f'``{name}``', + # [1:-1] drops the surrounding parentheses. + str(inspect.signature(cls))[1:-1] or 'None') + for name, cls in sorted(_styles.items())]] + # Convert to rst table. col_len = [max(len(cell) for cell in column) for column in zip(*table)] - table_formatstr = ' '.join('=' * cl for cl in col_len) - lines = [ + table_formatstr = ' '.join('=' * cl for cl in col_len) + rst_table = '\n'.join([ '', table_formatstr, - ' '.join(cell.ljust(cl) for cell, cl in zip(table[0], col_len)), + ' '.join(cell.ljust(cl) for cell, cl in zip(table[0], col_len)), table_formatstr, - *[' '.join(cell.ljust(cl) for cell, cl in zip(row, col_len)) + *[' '.join(cell.ljust(cl) for cell, cl in zip(row, col_len)) for row in table[1:]], table_formatstr, '', - ] - return textwrap.indent('\n'.join(lines), ' ' * leadingspace) - - -def _pprint_styles(_styles): - """ - A helper function for the _Style class. Given the dictionary of - {stylename: styleclass}, return a formatted string listing all the - styles. Used to update the documentation. - """ - import inspect - - _table = [["Class", "Name", "Attrs"]] - - for name, cls in sorted(_styles.items()): - spec = inspect.getfullargspec(cls.__init__) - if spec.defaults: - argstr = ", ".join(map( - "{}={}".format, spec.args[-len(spec.defaults):], spec.defaults - )) - else: - argstr = 'None' - # adding ``quotes`` since - and | have special meaning in reST - _table.append([cls.__name__, "``%s``" % name, argstr]) - - return _pprint_table(_table) + ]) + return textwrap.indent(rst_table, prefix=' ' * 2) def _simpleprint_styles(_styles):