Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

MNT: inspect.getfullargspec will be deprecated in py3.8#14138

Closed
tacaswell wants to merge 2 commits into
matplotlib:mastermatplotlib/matplotlib:masterfrom
tacaswell:mnt_py38_compattacaswell/matplotlib:mnt_py38_compatCopy head branch name to clipboard
Closed

MNT: inspect.getfullargspec will be deprecated in py3.8#14138
tacaswell wants to merge 2 commits into
matplotlib:mastermatplotlib/matplotlib:masterfrom
tacaswell:mnt_py38_compattacaswell/matplotlib:mnt_py38_compatCopy head branch name to clipboard

Conversation

@tacaswell

Copy link
Copy Markdown
Member

Switch to using inspect.signature

Still need to verify that the replacement is equivalent (which is why I marked it as draft), but pushing this out early so I don't forget I did this.

@tacaswell tacaswell added this to the v3.1.1 milestone May 6, 2019
Comment thread lib/matplotlib/artist.py Outdated
if not callable(func):
continue
nargs = len(inspect.getfullargspec(func).args)
nargs = len(inspect.signature(func).parameters)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Technically, this is not the same because Signature.parameters contains everything.

I think

len([p for p in inspect.signature(func).parameters.values()
    if p.kind == inspect.Parameter.POSITIONAL_OR_KEYWORD])

is equivalent, but haven't checked for cases with variable positional args or kwonly.

Some example code which may be useful to play around with:

>>> from pprint import pprint
>>> import inspect
>>> def f(a, b, c=0, **kwargs):
...     pass
... 
>>> inspect.getfullargspec(f)
FullArgSpec(args=['a', 'b', 'c'], varargs=None, varkw='kwargs', defaults=(0,), kwonlyargs=[], kwonlydefaults=None, annotations={})
>>> pprint(inspect.signature(f).parameters)
mappingproxy(OrderedDict([('a', <Parameter "a">),
                          ('b', <Parameter "b">),
                          ('c', <Parameter "c=0">),
                          ('kwargs', <Parameter "**kwargs">)]))

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.

However, the only thing we use nargs for is in the next line to detect if there if it less than 2 to detect if this is something that is named like a setter, but does not take enough arguments to actually be a setter.

@timhoffm timhoffm May 11, 2019

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

For the following

len(inspect.getfullargspec(func).args) < 2 is true but len(inspect.signature(func).parameters) < 2 is false:

Line2D.set_data(self, *args)
Axes.set_prop_cycle(self, *args, **kwargs)
Figure.set_constrained_layout_pads(self, **kwargs)

I did not check the full code path, but I assume they will be considered setters after the change - not sure if that's actually desired or not, but it's a change to be aware of.

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.

fair enough, will make the changes!

Thanks for pushing on this.

Comment thread lib/matplotlib/patches.py
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"

@cgohlke

cgohlke commented Jun 7, 2019

Copy link
Copy Markdown
Contributor

Looks like getfullargspec has been undeprecated python/cpython#13245

@timhoffm

timhoffm commented Aug 5, 2019

Copy link
Copy Markdown
Member

Superseeded by #14962.

@timhoffm timhoffm closed this Aug 5, 2019
@tacaswell tacaswell deleted the mnt_py38_compat branch August 5, 2019 17:09
@QuLogic QuLogic removed this from the v3.2.0 milestone Aug 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.