Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

[Experiement] Auto-expand signature when **kwarg passed to other functions#14857

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
Carreau wants to merge1 commit intomatplotlib:mainfromCarreau:expand-kwargs

Conversation

Carreau
Copy link
Contributor

Many functions current takes**kwargs and pass them down. During a SciPy
discussion it was brought up that this was sub-optimal for new user.

We can use the fact that signature can be faked, and inspect to
propagate the actual keyword arguments and substitute them for**kwargs
in another.

With this, the signature of pyplot.subplots(), which currently as viewed
in IPython is

plt.subplots(    nrows=1,    ncols=1,    sharex=False,    sharey=False,    squeeze=True,    subplot_kw=None,    gridspec_kw=None,    **fig_kw,)

now becomes:

plt.subplots(    nrows=1,    ncols=1,    sharex=False,    sharey=False,    squeeze=True,    subplot_kw=None,    gridspec_kw=None,+   num=None,+   figsize=None,+   dpi=None,+   facecolor=None,+   edgecolor=None,+   frameon=True,+   FigureClass=<class 'matplotlib.figure.Figure'>,+   clear=False,+   **kwargs, # used to be **fig_kw, to fix.)

... which is not totally correct (they are kwargs only...) but you
should see the point.

This is nice as:

  1. it now appear in IPython ? and ??
  2. tab completion pick up these kwargs.

And it should have minimal overhead at import time, and is so far
limited to function that pass all of **kwarg.

Many places in matplotlib are also too dynamic to properly do it, but
could allow a manual variant.

--

I'm not sure with who I talked about this at scipy – I believe@rabernat was there (?) and can remind me.

pharshalp reacted with thumbs up emoji
…tions.Many functions current takes **kwargs and pass them down. During a SciPydiscussion it was brought up that this was sub-optimal for new user.We can use the fact that signature can be faked, and inspect topropagate the actual keyword arguments and substitute them for **kwargsin another.With this, the signature of pyplot.subplots(), which currently as viewedin IPython is    plt.subplots(        nrows=1,        ncols=1,        sharex=False,        sharey=False,        squeeze=True,        subplot_kw=None,        gridspec_kw=None,        **fig_kw,    )now becomes:    plt.subplots(        nrows=1,        ncols=1,        sharex=False,        sharey=False,        squeeze=True,        subplot_kw=None,        gridspec_kw=None,    +   num=None,    +   figsize=None,    +   dpi=None,    +   facecolor=None,    +   edgecolor=None,    +   frameon=True,    +   FigureClass=<class 'matplotlib.figure.Figure'>,    +   clear=False,    +   **kwargs, # used to be **fig_kw, to fix.    )... which is not totally correct (they are kwargs only...) but youshould see the point.This is nice as:1) it now appear in IPython ? and ??2) tab completion pick up these kwargs.And it should have minimal overhead at import time, and is so farlimited to function that pass all of **kwarg.Many places in matplotlib are also too dynamic to properly do it, butcould allow a manual variant.
@jklymakjklymak added the status: needs comment/discussionneeds consensus on next step labelJul 19, 2019
@timhoffm
Copy link
Member

This is an interesting approach 👍. Some things to consider:

We have at least two common cases of kwargs:

  1. Accepts the same kwargs as , e.g.
    https://matplotlib.org/devdocs/api/_as_gen/matplotlib.pyplot.subplots.html
  2. Accepts some Artists properties, e.g.
    https://matplotlib.org/devdocs/api/_as_gen/matplotlib.axes.Axes.quiver.html

Configurability

In particular with the artists properties it would be nice to have additional freedom to specify the added parameters. For example inhttps://matplotlib.org/devdocs/api/_as_gen/matplotlib.axes.Axes.quiver.html the propertyarray does not make sense.

We probably need a variant which replaces kwargs exhaustingly and one which keeps kwargs for further paramters.

Effect on documentation

This will also add the parameters to the signature in the documentation:
https://23449-1385122-gh.circle-artifacts.com/0/home/circleci/project/doc/build/html/api/_as_gen/matplotlib.pyplot.subplots.html?highlight=subplots#matplotlib.pyplot.subplots

I don't think that's reasonable as it's getting very verbose and the signature does not match the docstring anymore. While one could consider some additional docstring rewriting for this. I wouldn't go down that road for now. I propose to add a flag so that this can be deactivated for the doc build.

@matthew-brett
Copy link
Contributor

During a SciPy discussion it was brought up that this was sub-optimal for new user.

Me too!

@Carreau
Copy link
ContributorAuthor

We probably need a variant which replaces kwargs exhaustingly and one which keeps kwargs for further paramters.

Yes, I believe anexclude=, orinclude_only= parameter is relatively easy. I'd still wan to be careful of not making it too complicated or too time consuming.

If it's equivalent in time as duplicating all the key word argument in the function signature instead of **kwargs, it may not be worth it.

This will also add the parameters to the signature in the documentation

I figured as much – as for messing with the docstring I'm not a fan of it either.

but again this is more a "hey this can be done, and it might be useful"; i'm going to assume matplotlib is not the only project that would need it; and it may be nice to have some of that as an external reusable package.

@tacaswelltacaswell added this to thev3.3.0 milestoneAug 24, 2019
@QuLogicQuLogic modified the milestones:v3.3.0,v3.4.0May 2, 2020
@QuLogicQuLogic modified the milestones:v3.4.0,v3.5.0Jan 22, 2021
@jklymakjklymak marked this pull request as draftMay 8, 2021 17:38
@QuLogicQuLogic modified the milestones:v3.5.0,v3.6.0Aug 18, 2021
@timhoffmtimhoffm modified the milestones:v3.6.0,unassignedApr 30, 2022
@story645story645 modified the milestones:unassigned,needs sortingOct 6, 2022
@github-actions
Copy link

Since this Pull Request has not been updated in 60 days, it has been marked "inactive." This does not mean that it will be closed, though it may be moved to a "Draft" state. This helps maintainers prioritize their reviewing efforts. You can pick the PR back up anytime - please ping us if you need a review or guidance to move the PR forward! If you do not plan on continuing the work, please let us know so that we can either find someone to take the PR over, or close it.

@github-actionsgithub-actionsbot added the status: inactiveMarked by the “Stale” Github Action labelJun 23, 2023
@Carreau
Copy link
ContributorAuthor

Closing to clean things up, anyone feel free to takover.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
status: inactiveMarked by the “Stale” Github Actionstatus: needs comment/discussionneeds consensus on next stepstatus: needs rebase
Projects
None yet
Milestone
future releases
Development

Successfully merging this pull request may close these issues.

7 participants
@Carreau@timhoffm@matthew-brett@tacaswell@QuLogic@story645@jklymak

[8]ページ先頭

©2009-2025 Movatter.jp