Repository navigation
Allow eval and exec to take keyword arguments #105879
Copy link
Copy link
Closed
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancementA feature request or enhancement
Description
Activity
- addedtype-featureA feature request or enhancementA feature request or enhancement
on Jun 17, 2023 - changed the title
[-]Alow eval and exec to take keyword arguments[/-][+]Allow eval and exec to take keyword arguments[/+]on Jun 17, 2023 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
evalnow has a bit more parsing code, butexecalready has support for one kwarg, so we're still looking at the same order of magnitude of instructions or existing code IMO.Make a PR :)
Created the PR, and tests seem to be passing now
- addedinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
on Nov 27, 2023 This will be in Python 3.13, thank you!
Reacted by Raphael Gaschignard and ૮༼⚆︿⚆༽つ- added a commit that references this issue
on Sep 10, 2024
Metadata
Metadata
Assignees
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancementA feature request or enhancement
Feature or enhancement
Allow for
globalsandlocalsto be passed in as keyword arguments toexecandeval.Pitch
execandevalboth can takeglobalsandlocalsas 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/execnow that we would explicitly disallow kwargs.Previous discussion
I sent this email to
python-ideasExtra 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