[issue24637] locals dictionary in PyRun_String
New submission from Matthew Keeter: 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-L62... [2] https://github.com/python/cpython/blob/master/Lib/test/test_builtin.py#L473 ---------- assignee: docs@python components: Documentation files: locals.patch keywords: patch messages: 246761 nosy: Matthew Keeter, docs@python priority: normal severity: normal status: open title: locals dictionary in PyRun_String type: enhancement versions: Python 2.7, Python 3.2, Python 3.3, Python 3.4, Python 3.5, Python 3.6 Added file: http://bugs.python.org/file39929/locals.patch _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue24637> _______________________________________
Changes by Berker Peksag <berker.peksag@gmail.com>: ---------- nosy: +berker.peksag stage: -> patch review versions: -Python 2.7, Python 3.2, Python 3.3, Python 3.4 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue24637> _______________________________________
Stéphane Wirtel added the comment: the patch makes sense for me. ---------- nosy: +matrixise _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue24637> _______________________________________
Roundup Robot added the comment: 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 ---------- nosy: +python-dev _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue24637> _______________________________________
Berker Peksag added the comment: Thanks for the patch, Matthew! ---------- resolution: -> fixed stage: patch review -> resolved status: open -> closed _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue24637> _______________________________________
participants (4)
-
Berker Peksag
-
Matthew Keeter
-
Roundup Robot
-
Stéphane Wirtel