Issue 7141: 2to3 should add from future import print_statement (original) (raw)

Created on 2009-10-15 15:28 by stutzbach, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (9)
msg94093 - (view) Author: Daniel Stutzbach (stutzbach) (Python committer) Date: 2009-10-15 15:28
I'm in the process of converting several Python scripts so that they work under both Python 2.6 and 3.1. For the most part, 2to3 does an amazing job. Great tool. One little feature request: could we make it add "from __future__ import print_statement" to the top of files? That one change is enough to make >95% of my converted scripts work fine under 2.6 and 3.1 instead of just 3.1.
msg112627 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2010-08-03 16:50
@Daniel there's far chance of this happening if you could provide a patch.
msg115278 - (view) Author: Daniel Stutzbach (stutzbach) (Python committer) Date: 2010-08-31 21:53
I don't think I'm familiar enough with 2to3's pattern-matching syntax to write a good patch. Here's a rough outline for how a patch would work. There are two cases: 1) When there is already a "from __future__ import". Currently, this line is stripped by fix_future. fix_future could be changed to remove the other futures, but add/leave "print_statement". This case is probably pretty straightforward. 2) When there is no "from __future__ import". A pattern would need to detect the absence of the __future__ line and insert one in the right place (after initial comments but before anything else).
msg115352 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2010-09-02 01:30
I don't think this is very useful. You could just as well exclude the future fixer completely.
msg115353 - (view) Author: Daniel Stutzbach (stutzbach) (Python committer) Date: 2010-09-02 01:35
Excluding the future fixer would only get me half of the way there. I would still need to add "from __future__ import print_statement" to all of my scripts if I want them to continue to work under 2.6. (Well, for me personally, I have already done exactly that, by hand. Rather tedious.)
msg115355 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2010-09-02 01:37
2010/9/1 Daniel Stutzbach <report@bugs.python.org>: > > Daniel Stutzbach <daniel@stutzbachenterprises.com> added the comment: > > Excluding the future fixer would only get me half of the way there.  I would still need to add "from __future__ import print_statement" to all of my scripts if I want them to continue to work under 2.6. I'm still apprehensive because it's not really the point of 2to3 to port apps to 2.6.
msg115356 - (view) Author: Daniel Stutzbach (stutzbach) (Python committer) Date: 2010-09-02 02:26
Well, I grant you that it's a bit of scope-creep, and if you want to reject it on those grounds I can't blame you. To me it seems like a relatively small change that would greatly help people like myself who want to update older code so that it will run under 2.6, 2.7, and 3.1+. Of course, since I don't know how to make the change, I could also be wrong about how easy it would be for a knowledgeable person to fit it into the existing 2to3 framework.
msg115362 - (view) Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) Date: 2010-09-02 08:57
> it's not really the point of 2to3 to port apps to 2.6. +1
msg115410 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2010-09-03 00:50
I rejecting, mostly to avoid feature creep. (This shouldn't be too difficult to accomplish with a shell script.) You could also look at 3to2.
History
Date User Action Args
2022-04-11 14:56:54 admin set github: 51390
2010-09-03 00:50:09 benjamin.peterson set status: open -> closedresolution: rejectedmessages: +
2010-09-02 08:57:18 giampaolo.rodola set nosy: + giampaolo.rodolamessages: +
2010-09-02 02:26:16 stutzbach set messages: +
2010-09-02 01:37:24 benjamin.peterson set messages: +
2010-09-02 01:35:34 stutzbach set messages: +
2010-09-02 01:30:01 benjamin.peterson set messages: +
2010-08-31 21:53:22 stutzbach set messages: + stage: needs patch
2010-08-03 16:50:00 BreamoreBoy set nosy: + BreamoreBoymessages: + versions: - Python 2.7
2010-08-03 14:17:02 djc set nosy: + djc
2009-10-15 15:39:13 georg.brandl set assignee: benjamin.petersonnosy: + benjamin.peterson
2009-10-15 15:28:32 stutzbach create