GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Allow eval and exec to take keyword arguments · Issue #105879 · python/cpython

Allow eval and exec to take keyword arguments #105879

New issue
Copy link
New issue
Copy link
Closed
Closed
Allow eval and exec to take keyword arguments#105879
Copy link
Assignees
JelleZijlstra
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

@rtpg
rtpg
opened on Jun 17, 2023
Issue body actions

Feature or enhancement

Allow for globals and locals to be passed in as keyword arguments to exec and eval.

Pitch

exec and eval both can take globals and locals 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

  • gh-105879: Add support for keyword arguments to eval and exec #105885
  • GH-105879: Note exec/eval keyword change in What's New #121831
  • [3.13] GH-105879: Note exec/eval keyword change in What's New (GH-121831) #121852
Reacted by Jelle Zijlstra

Activity

  1. rtpg
    added
    type-featureA feature request or enhancementA feature request or enhancement
    on Jun 17, 2023
  2. JelleZijlstra
    changed the title [-]Alow eval and exec to take keyword arguments[/-] [+]Allow eval and exec to take keyword arguments[/+] on Jun 17, 2023
  3. sunmy2019 commented on Jun 17, 2023

    @sunmy2019
    sunmy2019
    on Jun 17, 2023
    Member
    More actions

    My concern is, will this hurt performance a lot?

  4. JelleZijlstra commented on Jun 17, 2023

    @JelleZijlstra
    JelleZijlstra
    on Jun 17, 2023
    Member
    More actions

    We can benchmark it, but that seems unlikely; parsing code is probably a lot slower than accepting some keyword arguments.

  5. rtpg commented on Jun 17, 2023

    @rtpg
    rtpg
    on Jun 17, 2023
    ContributorAuthor
    More actions

    @sunmy2019 I added a link to a commit implementing this. The short version is eval now has a bit more parsing code, but exec already has support for one kwarg, so we're still looking at the same order of magnitude of instructions or existing code IMO.

  6. JelleZijlstra commented on Jun 17, 2023

    @JelleZijlstra
    JelleZijlstra
    on Jun 17, 2023
    Member
    More actions

    Make a PR :)

  7. rtpg commented on Jun 19, 2023

    @rtpg
    rtpg
    on Jun 19, 2023
    ContributorAuthor
    More actions

    Created the PR, and tests seem to be passing now

  8. iritkatriel
    added
    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
    on Nov 27, 2023
  9. JelleZijlstra
    self-assigned this
    on May 1, 2024
  10. JelleZijlstra
    added a commit that references this issue on May 2, 2024

    gh-105879: Add support for keyword arguments to eval and exec (#105885)

    2770d5c
  11. JelleZijlstra commented on May 2, 2024

    @JelleZijlstra
    JelleZijlstra
    on May 2, 2024
    Member
    More actions

    This will be in Python 3.13, thank you!

    Reacted by Raphael Gaschignard and ૮༼⚆︿⚆༽つ
  12. JelleZijlstra
    closed this as completedon May 2, 2024
  13. SonicField
    added a commit that references this issue on May 8, 2024

    pythongh-105879: Add support for keyword arguments to eval and exec (p…

    b2ff973
  14. ncoghlan
    added a commit that references this issue on Jul 16, 2024

    GH-105879: Note exec/eval keyword change in What's New (GH-121831)

    d7a099d
  15. miss-islington
    added a commit that references this issue on Jul 16, 2024

    pythonGH-105879: Note exec/eval keyword change in What's New (pythonG…

    8cb9780
  16. ncoghlan
    added a commit that references this issue on Jul 16, 2024

    [3.13] GH-105879: Note exec/eval keyword change in What's New (GH-121831

    c11d789
  17. estyxx
    added a commit that references this issue on Jul 17, 2024

    pythonGH-105879: Note exec/eval keyword change in What's New (pythonG…

    38c99dc
  18. JelleZijlstra
    added a commit that references this issue on Sep 10, 2024

    Add support for keyword arguments to eval and exec (python#105879)

    c4368ef
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @JelleZijlstra
    JelleZijlstra

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

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.