-
-
Notifications
You must be signed in to change notification settings - Fork 30.3k
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 <[email protected]>
* Clarify impact on default behaviour of exec, eval, etc * Update documentation for changes to PyEval_GetLocals (gh-74929) Closes gh-118888 (cherry picked from commit 2180991) Co-authored-by: Alyssa Coghlan <[email protected]>
* 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
*Changes made* - Update `setup.py` to pass in a local dictionary to `exec` to capture the `locals()` in `_version.py` for package version reporting. *Motivation* - `Python3.13.0` enforces stricter safety standards on `locals()` with PEP 667 (see [here](python/cpython#118888 (comment))) - This causes the following error upon attempting to install with `python3.13 -m pip install openai-whisper`: ```bash Collecting openai-whisper Using cached openai-whisper-20240930.tar.gz (800 kB) Installing build dependencies ... done Getting requirements to build wheel ... error error: subprocess-exited-with-error × Getting requirements to build wheel did not run successfully. │ exit code: 1 ╰─> [25 lines of output] <string>:5: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html Traceback (most recent call last): File "/Users/jasonshipp/.pyenv/versions/3.13.0/lib/python3.13/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module> main() ~~~~^^ File "/Users/jasonshipp/.pyenv/versions/3.13.0/lib/python3.13/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main json_out['return_val'] = hook(**hook_input['kwargs']) ~~~~^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/jasonshipp/.pyenv/versions/3.13.0/lib/python3.13/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 118, in get_requires_for_build_wheel return hook(config_settings) File "/private/var/folders/hk/8xz63_l16zb9snz57jx9hqgr0000gn/T/pip-build-env-l_19mrvs/overlay/lib/python3.13/site-packages/setuptools/build_meta.py", line 332, in get_requires_for_build_wheel return self._get_build_requires(config_settings, requirements=[]) ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/private/var/folders/hk/8xz63_l16zb9snz57jx9hqgr0000gn/T/pip-build-env-l_19mrvs/overlay/lib/python3.13/site-packages/setuptools/build_meta.py", line 302, in _get_build_requires self.run_setup() ~~~~~~~~~~~~~~^^ File "/private/var/folders/hk/8xz63_l16zb9snz57jx9hqgr0000gn/T/pip-build-env-l_19mrvs/overlay/lib/python3.13/site-packages/setuptools/build_meta.py", line 516, in run_setup super().run_setup(setup_script=setup_script) ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/private/var/folders/hk/8xz63_l16zb9snz57jx9hqgr0000gn/T/pip-build-env-l_19mrvs/overlay/lib/python3.13/site-packages/setuptools/build_meta.py", line 318, in run_setup exec(code, locals()) ~~~~^^^^^^^^^^^^^^^^ File "<string>", line 21, in <module> File "<string>", line 11, in read_version KeyError: '__version__' [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. error: subprocess-exited-with-error × Getting requirements to build wheel did not run successfully. │ exit code: 1 ╰─> See above for output. note: This error originates from a subprocess, and is likely not a problem with pip ``` *EXTRA NOTES* - This does not enable `openai-whisper` to be pip installed with `Python3.13`, due to a dependency on the `numba` library. This issue and missing dependency can be tracked [here](numba/numba#9413)
This includes a backport of python-pillow/Pillow#8050 (python-pillow/Pillow@57399ce) from Pillow 10.4.0, necessary for Python 3.13 compatibility. See python/cpython#118888.
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: