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@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 <rep...@bugs.python.org>
<http://bugs.python.org/issue24637>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to