-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Functions should list explicit keyword arguments when possible #14030
Comments
Oh apparently |
In some instances this won't be possible, because keyword arguments after |
+1, some reference can be seen here but in python 3 keyword arguments can be used after |
Yes, all code in SymPy must work in both Python 2 and Python 3 for now. |
What functions do we need to change? |
@asmeurer should I try in replace in whole modules or in some modules? |
@vivonk One module at a time may be a good approach. Easier to review. (E.g., physics module, or geometry module, or solvers module, etc) |
Is it mean that if the |
In that example, If something else was indeed passing keyword arguments to the function, then **kwargs should not be just removed; that would raise "unexpected keyword argument" error. In such a situation one has to consider why something is passing an argument that the function ignores. |
Is this issue #13683 to similar to this? |
@normalhuman @asmeurer I am facing a problem. In some cases it is like
|
@gxyd yes that issue is related. In the case of #13683, there are functions that use |
This is what I meant by "passed through". In those cases, it is generally best to leave the
All new keyword arguments should be put after the existing ones. Once we drop Python 2 support, we can make these keyword arguments keyword-only so that the order doesn't matter. For now, we have to use some order. In the case of something like Also, don't put spaces around |
@asmeurer got your point. Thanks to clear it |
I think in cases passing through |
I agree such options refactoring would be nice. However it's a lot more refactoring than the basic change I am talking about here (definitely not "easy to fix"). |
and imporove documentation. See issue sympy#14030
partial fix for sympy#14030
is this still needs work? |
@asmeurer @friyaz Please confirm if I have understood it right. |
The use of |
Thanks for replying @asmeurer . Before I proceed can you just confirm whether my perception is correct with the help of following examples:
Here options is passed to another function inside body , so nothing needs to be done. (Keep **options as it is).
Here **kwargs can be removed since it is not used in the body at all.
Here **kwargs should be replaced with (evaluate=global_parameters.evaluate) |
I had left some comment in #25752 that the correct way to migrate the existing code after PEP-3102
is not using
but using
should be the correct and isomorphic way to migrate code without breaking any backward compatibiity,
I'm just adding this guide because it is not very easy to find this info, unless you can consult some other advices from experienced programmers in Python, because it is not written in most of the tutorials about using niche features like PEP-3102 |
@sylee957 the default value of the second argument to >>> print({}.get('x'))
None So changing Required keyword arguments should be a fairly rare thing to want to include in a signature. |
Why? |
I may got trivially wrong about kwargs.get, Also, in the original PR I linked to, default values None doesn't make sense anyway, so for that specific case, I would defend my argument |
Anyway, I think that the major problem is having poorly defined API based on kwargs, bad ergonomics, I don't think that I would agree that sympy should have indefinite API that relies on **kwargs. This can misguide people that they can extend the features indefinitely, which follows up with a poor effort to document about the API. I haven't counted on, but I have seen fairly many sympy functions to have **kwargs without what is about, or partially documented. |
I think that having this as an "easy to fix" issue is not helpful. It could be considered suitable for a new contributor if there was a clear list of which functions to change but there are lots of functions that take |
I agree that we should remove easy-to-fix. |
@sylee957 @asmeurer @oscarbenjamin |
Whenever possible, functions should list the explicit keyword arguments in their signature, rather than using
**kwargs
. Furthermore, if**kwargs
is not passed through to anything, it should not be used. This makes the functions more self documenting to things likehelp()
and?
in IPython that show the signature, and it helps avoid silent typo errors.This is an example of what I'm talking about.
I noticed this for instance in
legendre_poly
, which has**args
but only uses thepolys
flag, but I know there are plenty of other instances all over the codebase.The text was updated successfully, but these errors were encountered: