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: Document "exec(stmt, global_dict, local_dict)" form in Python 2?
Type: Stage: patch review
Components: Documentation Versions: Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: mark.dickinson Nosy List: docs@python, mark.dickinson, python-dev
Priority: normal Keywords: easy, patch

Created on 2012-10-27 17:31 by mark.dickinson, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
issue16339.patch mark.dickinson, 2012-11-25 11:07 review
issue16339_v2.patch mark.dickinson, 2012-11-25 11:59 review
issue16339_v3.patch mark.dickinson, 2012-11-25 12:06 review
Messages (6)
msg173947 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2012-10-27 17:31
In Python 2, the 'exec' statement supports 'exec'-ing a (statement, globals, locals) tuple:

>>> exec("print 2", {}, {})
2

This doesn't seem to be documented at http://docs.python.org/reference/simple_stmts.html#the-exec-statement.

If I understand correctly, the 'exec tuple' form was originally there for backwards compatibility with ancient versions of Python;  however, it now also conveniently provides the semblance of forwards compatibility with Python 3.  It appears to be supported by current versions of Jython (though judging by issue 403345 that wasn't always the case) and PyPy.

Is this omission intentional?  Is this form of exec an official, supported part of the Python 2 language?
msg174906 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2012-11-05 13:11
Thread on #python-dev:  http://mail.python.org/pipermail/python-dev/2012-November/122543.html

If this is documented, direct tests for this form of exec should also be added.
msg176339 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2012-11-25 11:06
Here's a patch for the documentation and tests.
msg176342 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2012-11-25 11:59
Updated patch:  drops mention of backwards compatibility, since that's not so useful (thanks, Ezio!).  Adds note about resemblance to Python 3 code.
msg176343 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2012-11-25 12:06
Rewording the sentence about Python 3.
msg176349 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2012-11-25 13:26
New changeset fd9c9579050d by Mark Dickinson in branch '2.7':
Issue #16339: Document and test exec(stmt, globals, locals) form in Python 2.7.
http://hg.python.org/cpython/rev/fd9c9579050d
History
Date User Action Args
2022-04-11 14:57:37adminsetgithub: 60543
2012-11-25 13:28:33mark.dickinsonsetstatus: open -> closed
resolution: fixed
2012-11-25 13:26:06python-devsetnosy: + python-dev
messages: + msg176349
2012-11-25 12:06:26mark.dickinsonsetfiles: + issue16339_v3.patch

messages: + msg176343
2012-11-25 11:59:22mark.dickinsonsetfiles: + issue16339_v2.patch

messages: + msg176342
2012-11-25 11:23:38mark.dickinsonsetstage: needs patch -> patch review
2012-11-25 11:07:35mark.dickinsonsetfiles: - issue16339.patch
2012-11-25 11:07:26mark.dickinsonsetfiles: + issue16339.patch
2012-11-25 11:06:31mark.dickinsonsetfiles: + issue16339.patch
keywords: + patch
messages: + msg176339
2012-11-13 09:03:20mark.dickinsonsetassignee: docs@python -> mark.dickinson
2012-11-05 13:11:29mark.dickinsonsetmessages: + msg174906
2012-11-03 21:11:57ezio.melottisetkeywords: + easy
2012-10-27 17:31:07mark.dickinsoncreate