Skip to content
Closed
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
3 changes: 2 additions & 1 deletion lib/matplotlib/artist.py
Original file line number Diff line number Diff line change
Expand Up @@ -1270,7 +1270,8 @@ def _get_setters_and_targets(self):
func = getattr(self.o, name)
if not callable(func):
continue
nargs = len(inspect.getfullargspec(func).args)
nargs = len([p for p in inspect.signature(func).parameters.values()
if p.kind == inspect.Parameter.POSITIONAL_OR_KEYWORD])
if nargs < 2 or self.is_alias(func):
continue
source_class = self.o.__module__ + "." + self.o.__name__
Expand Down
11 changes: 5 additions & 6 deletions lib/matplotlib/patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -1863,12 +1863,11 @@ def _pprint_styles(_styles):
_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:
sig = inspect.signature(cls.__init__)
argstr = ", ".join(
f"{p.name}={p.default}"

@anntzer anntzer May 14, 2019

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually that's just str(p) (which will print out as name=default in presence of a default, isn't the stdlib wonderful? :p)


and the whole thing can be simplified down to

        argstr = (str(inspect.signature(cls))[1:-1]  # Strip parentheses.
                  or "None")

because style classes don't take other arguments, and inspect.signature(cls) helpfully drops self from the signature of __init__...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"if something seems like it is too hard, it probably is"

for p in sig.parameters.values() if p.default is not p.empty)
if not argstr:
argstr = 'None'
# adding ``quotes`` since - and | have special meaning in reST
_table.append([cls.__name__, "``%s``" % name, argstr])
Expand Down