This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: locals dictionary in PyRun_String
Type: enhancement Stage: resolved
Components: Documentation Versions: Python 3.6, Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: Matthew Keeter, berker.peksag, docs@python, matrixise, python-dev
Priority: normal Keywords: patch

Created on 2015-07-15 13:23 by Matthew Keeter, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
locals.patch Matthew Keeter, 2015-07-15 13:23 review
Messages (4)
msg246761 - (view) Author: Matthew Keeter (Matthew Keeter) Date: 2015-07-15 13:23
The C API docs for PyRun_StringFlags, PyEval_EvalCodeEx, and PyEval_EvalCode say that globals and locals both must be dictionaries.  However, digging into the source [1] shows that locals can be any object implementing the mapping protocol.  Furthermore, the Python docs for eval and exec (which end up taking the same path) match the implementation, saying that locals can be any mapping object (which has been true since 2.4).

The attached patch changes the C API docs to reflect the Python docs (and the actual implementation).  No new tests are required, as test_general_eval [2] already checks that an arbitrary mapping object can be used as the locals variable in exec.

[1] https://github.com/python/cpython/blob/master/Objects/frameobject.c#L628-L629
[2] https://github.com/python/cpython/blob/master/Lib/test/test_builtin.py#L473
msg271830 - (view) Author: Stéphane Wirtel (matrixise) * (Python committer) Date: 2016-08-02 16:32
the patch makes sense for me.
msg272575 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-08-13 02:38
New changeset 0f2a09950ac8 by Berker Peksag in branch '3.5':
Issue #24637: Document that locals can be any mapping object
https://hg.python.org/cpython/rev/0f2a09950ac8

New changeset 61c4dbec2e2c by Berker Peksag in branch 'default':
Issue #24637: Merge from 3.5
https://hg.python.org/cpython/rev/61c4dbec2e2c
msg272576 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2016-08-13 02:39
Thanks for the patch, Matthew!
History
Date User Action Args
2022-04-11 14:58:18adminsetgithub: 68825
2016-08-13 02:39:20berker.peksagsetstatus: open -> closed
resolution: fixed
messages: + msg272576

stage: patch review -> resolved
2016-08-13 02:38:17python-devsetnosy: + python-dev
messages: + msg272575
2016-08-02 16:32:54matrixisesetnosy: + matrixise
messages: + msg271830
2016-08-02 16:25:49berker.peksagsetnosy: + berker.peksag
stage: patch review

versions: - Python 2.7, Python 3.2, Python 3.3, Python 3.4
2015-07-15 13:23:06Matthew Keetercreate