← 返回首页
Python 3.13.0b1: exec() does not populate locals() · Issue #118888 · python/cpython · GitHub
Skip to content

Navigation Menu

Toggle navigation
Sign in
Appearance settings
Search or jump to...

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Include my email address so I can be contacted

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Resetting focus

Python 3.13.0b1: exec() does not populate locals() #118888

New issue
New issue

Description

Bug report

Bug description:

x.py

xxx = 118888

readx.py

def f(): with open("x.py", encoding="utf-8") as f: exec(compile(f.read(), "x.py", "exec")) return locals()["xxx"] print(f())

shell

$ python3.12 readx.py 118888 $ python3.13 readx.py Traceback (most recent call last): File ".../readx.py", line 6, in <module> print(f()) ~^^ File ".../readx.py", line 4, in f return locals()["xxx"] ~~~~~~~~^^^^^^^ KeyError: 'xxx'

This breaks e.g. pillow 10.3.0 which has:

def get_version(): version_file = "src/PIL/_version.py" with open(version_file, encoding="utf-8") as f: exec(compile(f.read(), version_file, "exec")) return locals()["__version__"]

In https://github.com/python-pillow/Pillow/blob/10.3.0/setup.py#L23

CPython versions tested on:

3.13

Operating systems tested on:

Linux

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13bugs and security fixes3.14bugs and security fixesdocsDocumentation in the Doc dir

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    • Open in GitHub Copilot app

    Footer

    © 2026 GitHub, Inc.