-
-
Notifications
You must be signed in to change notification settings - Fork 535
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
Enforce keyword-only parameters, with deprecation #16607
Comments
comment:2
-1 for performance reasons. Calls in python are expensive and wrappers installed by decorators add a call level. And sage tends to have a lot of calls already, so these costs quickly add up. There would be a way to have both: have a flag set at startup that determines whether the decorator puts a check in place or just returns the original function. I'm afraid that's too complicated to be used in practice, though, but you could try. |
comment:3
Replying to @nbruin:
I am thinking about things which are unlikely to be used in a tight loop. Front ends to costly operations, mostly. In those case, the extra cost would be negligible compared to the typical cost of the function execution. I certainly wouldn't want to add this decorator to every function that might syntactically qualify, exactly due to these performance issues. I'd say the decorator should only be used if there is considerable gain associated with dropping a positional parameter.
This might help when policing uses within Sage itself. My main concern however was user interaction. If we leave them an officially sanctioned option to disable the checks, then we might be responsible to maintain compatibility with deprecated syntax indefinitely. Unless we have the checks in place by default and make a very clear statement that people must assume responsibility if they decide to disable them. Checks enabled by default would change little in terms of performance for most users. |
Branch: u/gagern/ticket/16607 |
Commit: |
comment:5
OK, here is my implementation. With a big fat warning about performance considerations, to reduce the chances of inappropriate use. In #15515 comment:16 I had to undo some changes by Jeroen Demeyer to avoid breaking compatibility for positional arguments. So it seems I'm not the only one who would like to get rid of some positional parameters to simplify implementations. With this tool here, we can have a proper deprecation period before we can finally dump them. And with the New commits:
|
Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:
|
Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:
|
Author: Martin von Gagern |
comment:10
I feel like the issue in the ticket is not serious enough to require such a heavy-handed solution. So I'm leaning towards "wontfix". Note that Cython files do actually support the PEP 3102 syntax even for Python 2. |
comment:11
Replying to @jdemeyer:
In #17234 comment:16 you yourself had to remind people to not break positional parameter compatibility. So this looks like a recurring theme. And just because we have this tool here doesn't mean anyone will be forced to use it. But people may use it instead of inventing new workarounds at every turn.
That is good to know, thanks! |
comment:12
Nils, do you have any more comments about this? For PEP links in Sphinx, you can use |
comment:13
Also: do you have a particular use-case in mind? If yes, please add this new decorator to an existing method, such that people can see how it is used in "real" situations. |
comment:14
Replying to @gagern:
You should probably add this as a comment somewhere. |
comment:16
Looks good to me. Its just a temporary measure anyways, we'll rip it out when we move to Python 3 |
Reviewer: Volker Braun |
comment:17
|
comment:22
This looks better now. Sorry I hadn't tested this as well as I should have before. |
comment:23
Needs to be rebased on sage8.1beta3 |
comment:25
Now, after the switch to Python 3, we could revisit this. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
comment:29
Setting new milestone based on a cursory review of ticket status, priority, and last modification date. |
comment:30
Setting a new milestone for this ticket based on a cursory review. |
There are functions all over the library which accept various optional named parameters. Often the intention is that these will only be used as keyword parameters, but that fact is not enforced. Maintaining a huge number of possibly positional parameters can become a maintenance pain. (I'm currently seeing a mild version of this in #16533, but things could be much worse.)
PEP 3102 introduced syntax for this for Python 3.
This ticket introduces a decorator which will limit the number of positional parameters passed to its wrapped function.
To faciliate graceful deprecation, it might be associated with a trac ticket number and pass extra positional arguments after issuing a deprecation warning.
After the deprecation period, it would be replaced by proper keyword-only parameters.
Because of the performance penalty of the decorator, this should be done only for non-performance critical functions.
We demonstrate the use of the decorator on this ticket with a number of examples:
get_solver - this would catch the typical user error
get_solver('GLPK')
more TBD.
CC: @nilesjohnson @fchapoton @mwageringel
Component: misc
Author: Martin von Gagern
Branch/Commit: u/gagern/ticket/16607 @
9755cda
Reviewer: Volker Braun
Issue created by migration from https://trac.sagemath.org/ticket/16607
The text was updated successfully, but these errors were encountered: