classification
Title: reflect syntatic sugar in with ast
Type: enhancement Stage: resolved
Components: Interpreter Core Versions: Python 3.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: amaury.forgeotdarc, benjamin.peterson, ezio.melotti, ncoghlan, python-dev
Priority: normal Keywords: patch

Created on 2011-05-18 21:45 by benjamin.peterson, last changed 2011-05-28 12:00 by ezio.melotti. This issue is now closed.

Files
File name Uploaded Description Edit
fixwith.patch benjamin.peterson, 2011-05-18 21:45 review
fixwith2.patch benjamin.peterson, 2011-05-25 00:25 review
Messages (11)
msg136262 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2011-05-18 21:45
This patch causes multiple with statements with multiple with items to be represented in the AST instead of flattened as currently happens.
msg136815 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2011-05-25 00:25
Here is an improved patch. Sans comments, I will apply in a few days.
msg136818 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2011-05-25 01:17
Just to articulate the rationale, I'm guessing the reasoning behind this is to make it feasible for source->AST->source translators to retain the original grouping?
msg136819 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2011-05-25 01:25
Visual scan of the patch in Reitveld looks fine to me.
msg136820 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2011-05-25 01:27
2011/5/24 Nick Coghlan <report@bugs.python.org>:
>
> Nick Coghlan <ncoghlan@gmail.com> added the comment:
>
> Just to articulate the rationale, I'm guessing the reasoning behind this is to make it feasible for source->AST->source translators to retain the original grouping?

Correct. It also allows my Python static analysis tool to detect when
someone could be using the double with shorthand instead of
nested-withs.
msg137095 - (view) Author: Roundup Robot (python-dev) Date: 2011-05-27 18:57
New changeset 9b11cc4e2918 by Benjamin Peterson in branch 'default':
reflect with statements with multiple items in the AST (closes #12106)
http://hg.python.org/cpython/rev/9b11cc4e2918
msg137117 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2011-05-28 10:22
Does this change have a visible effect? If so, can it have some unit test? Otherwise pypy and other alternative implementations are likely to miss this change.
msg137121 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2011-05-28 11:15
The AST version changed, and, more importantly, if other implementations pick up our AST changes without updating their compilers accordingly, their symbol table analysis and code compilation processes will break.

So yes, the test suite does already cover this change.

For the record:
3.2: ast.__version__ == 82163
3.3: ast.__version__ == 0daa6ba25d9b

(The latter is only the 3.3 AST version for the moment - there are additional AST cleanups planned for 3.3 now that the other projects gave their blessing to do so on python-dev)
msg137123 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2011-05-28 11:38
Thanks for this answer.
msg137124 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2011-05-28 11:50
One other thing I should mention is that in a later checkin, Benjamin did add a couple of explicit with statement examples to test_ast. These will fail if other implementations don't update the front end of their compilation processes correctly, so that should eliminate cases of counteracting bugs in the front end and back end.
msg137125 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2011-05-28 12:00
That would be c4ddb460f4f2.
History
Date User Action Args
2011-05-28 12:00:35ezio.melottisetnosy: + ezio.melotti
messages: + msg137125
2011-05-28 11:50:33ncoghlansetmessages: + msg137124
2011-05-28 11:38:28amaury.forgeotdarcsetmessages: + msg137123
2011-05-28 11:15:48ncoghlansetstatus: open -> closed

messages: + msg137121
2011-05-28 10:22:36amaury.forgeotdarcsetstatus: closed -> open
2011-05-28 10:22:16amaury.forgeotdarcsetnosy: + amaury.forgeotdarc
messages: + msg137117
2011-05-27 18:57:51python-devsetstatus: open -> closed

nosy: + python-dev
messages: + msg137095

resolution: fixed
stage: resolved
2011-05-25 01:27:31benjamin.petersonsetmessages: + msg136820
2011-05-25 01:25:11ncoghlansetmessages: + msg136819
2011-05-25 01:17:03ncoghlansetmessages: + msg136818
2011-05-25 00:25:55benjamin.petersonsetfiles: + fixwith2.patch

messages: + msg136815
2011-05-18 21:45:18benjamin.petersoncreate