-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Clarify how to use keyword arguments in FuncAnimation #24139
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
Conversation
@@ -1564,6 +1565,14 @@ def init_func() -> iterable_of_artists | |||
fargs : tuple or None, optional | |||
Additional arguments to pass to each call to *func*. | |||
|
|||
An option to *fargs* is to use `functools.partial`, with the added |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An option to *fargs* is to use `functools.partial`, with the added | |
An alternative to *fargs* is to use `functools.partial`, with the added |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
stealing some of the language/constructs from #20358 to make it clearer that partial is an alternative to fargs
arguments can be supplied via the *fargs* parameter. See *fargs* for | ||
how to use `functools.partial` to supply keyword arguments. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
arguments can be supplied via the *fargs* parameter. See *fargs* for | |
how to use `functools.partial` to supply keyword arguments. | |
arguments can be supplied using `functools.partial` or via the *fargs* parameter. |
Flipped because I think the functools version is preferred. I think it's gonna be clearer to add the information about partial in this section since it's passed in as the func keyword, Maybe after the required signature, something like:
To pass in a function with positional keywords, set func to the partial function::
func = partial(func, frame, **kwargs)
An option to *fargs* is to use `functools.partial`, with the added | ||
benefit of also supporting keyword arguments. An example is to pass | ||
something like:: | ||
|
||
partial(func, **kwargs) | ||
|
||
as *func*. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think if you move the intro of partial up to func, this can be simplified to
An option to *fargs* is to use `functools.partial`, with the added | |
benefit of also supporting keyword arguments. An example is to pass | |
something like:: | |
partial(func, **kwargs) | |
as *func*. | |
Passing in `functools.partial` as *func* is preferred to passing in *fargs* and supports keyword arguments. See *func* for an example. |
benefit of also supporting keyword arguments. An example is to pass | ||
something like:: | ||
|
||
partial(func, **kwargs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't you normally have the case that you want to set some kwargs explicitly? Then I suggest to make the example more concrete:
partial(func, **kwargs) | |
partial(func, my_kwarg='something') |
Maye even show a more complete FuncAnimation
call to show this fits in.
There is also #20358 which solves the same issue. I'll have a look and may go for extending that instead (the importance of linking PRs to issues...). |
PR Summary
Closes #20326
I didn't find a good animation example to modify...
PR Checklist
Tests and Styling
pytest
passes).flake8-docstrings
and runflake8 --docstring-convention=all
).Documentation
doc/users/next_whats_new/
(follow instructions in README.rst there).doc/api/next_api_changes/
(follow instructions in README.rst there).