-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
Allow eval and exec to take keyword arguments #105879
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
Comments
My concern is, will this hurt performance a lot? |
We can benchmark it, but that seems unlikely; parsing code is probably a lot slower than accepting some keyword arguments. |
@sunmy2019 I added a link to a commit implementing this. The short version is |
Make a PR :) |
Created the PR, and tests seem to be passing now |
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
This will be in Python 3.13, thank you! |
…ython#105885) Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Feature or enhancement
Allow for
globals
andlocals
to be passed in as keyword arguments toexec
andeval
.Pitch
exec
andeval
both can takeglobals
andlocals
as positional arguments.The built-in functions documentation shows the argument defaults, and every time I have the documentation open and am writing these, I default to keyword arguments, and it fails because the arguments are positional-only.
For functions like this that might only be present in a handful of places, kwargs give a good way to document what parameters each argument is referring to. I don't think that in a universe in which we were introducing
eval
/exec
now that we would explicitly disallow kwargs.Previous discussion
I sent this email to
python-ideas
Extra Links
Here is an implementation, which just consists in changing the argument clinic config and rerunning. I set up some very basic kwarg tests mostly to test the case of "locals provided but globals not provided", but fortunately the existing implementations already handled this cleanly!
Linked PRs
The text was updated successfully, but these errors were encountered: