8000 Replace inspect.getfullargspec by inspect.signature. by anntzer · Pull Request #14962 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Replace inspect.getfullargspec by inspect.signature. #14962

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 5 additions & 11 deletions lib/matplotlib/artist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
50 changes: 18 additions & 32 deletions lib/matplotlib/patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
0