-
-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
Python 3.13.0b1: exec() does not populate locals() #118888
Comments
Bisected to b034f14 |
This is an expected and intentional behavior change due to PEP 667. I won't even consider this is "breaking" as the docs clearly states:
So this is an illegal usage that happens to work in a favored way to begin with. If you want the result of the local changes, pass in an explicit dictionary: def get_version():
version_file = "src/PIL/_version.py"
d = {}
with open(version_file, encoding="utf-8") as f:
exec(compile(f.read(), version_file, "exec"), globals(), d)
return d["__version__"] I'm aware that this might be a bit inconvenience to the library maintainers, but this is the right way to go and we are making efforts to make |
It it true that the 3.12 docs say that readx.py should not be expected to work. But it did then and previously, even though not now. What's New 3.13 only says
From this, I would not expect changes in how locals() behaves, in particular in the effect of exec bindings. I think this should be mention. Even the Python subsection of the PEP's Back Compatibility section says nothing. It only mentions a couple of things that do not change. |
We are aware that the docs are not fully ready for beta 1, but this behavior is described in detail in |
Can this be closed now the docs were updated in #119201? |
Yeah, the function level snapshot behaviour is now covered in the What's New porting guide: https://docs.python.org/3.13/whatsnew/3.13.html#changes-in-the-python-api It is also mentioned in a versionchanged note on The general write-up of PEP 667 also mentions The most minimal change to fix this kind of Alternatively, for the examples given, https://docs.python.org/3/library/runpy.html#runpy.run_path is a better tool when the task is "run the Python file at this location and return its top level namespace" (it will respect Python source encoding declarations properly, while explicitly opening the files as utf-8 ignores them). |
Considering this further, I'm thinking it may be worth tweaking the text in "What's New" a bit, as somebody reading even the updated What's New entry might not make the leap from "the mutation semantics of |
Current plan for changes
|
No PR yet as I'll merge #119379 before making any further PEP 667 related updates. |
* Clarify impact on default behaviour of exec, eval, etc * Update documentation for changes to PyEval_GetLocals (pythongh-74929) Closes pythongh-11888 (cherry picked from commit 2180991) Co-authored-by: Alyssa Coghlan <ncoghlan@gmail.com>
* Clarify impact on default behaviour of exec, eval, etc * Update documentation for changes to PyEval_GetLocals (pythongh-74929) Closes pythongh-11888
* Clarify impact on default behaviour of exec, eval, etc * Update documentation for changes to PyEval_GetLocals (pythongh-74929) Closes pythongh-11888
* Clarify impact on default behaviour of exec, eval, etc * Update documentation for changes to PyEval_GetLocals (pythongh-74929) Closes pythongh-11888
Accessing __version__ from locals() no longer works. This was reported to Python in python/cpython#118888 but according to Python developers, it: - is an intended change of behavior described in PEP 667 - was an illegal usage that happens to work in a favored way to begin with
Bug report
Bug description:
x.py
readx.py
shell
This breaks e.g. pillow 10.3.0 which has:
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
The text was updated successfully, but these errors were encountered: