[New-bugs-announce] [issue24637] locals dictionary in PyRun_String

Matthew Keeter report at bugs.python.org
Wed Jul 15 15:23:06 CEST 2015


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-L629
[2] https://github.com/python/cpython/blob/master/Lib/test/test_builtin.py#L473

----------
assignee: docs at python
components: Documentation
files: locals.patch
keywords: patch
messages: 246761
nosy: Matthew Keeter, docs at 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 at bugs.python.org>
<http://bugs.python.org/issue24637>
_______________________________________


More information about the New-bugs-announce mailing list