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: 2to3 should add from __future__ import print_statement
Type: enhancement Stage: needs patch
Components: 2to3 (2.x to 3.x conversion tool) Versions: Python 3.2
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: benjamin.peterson Nosy List: BreamoreBoy, benjamin.peterson, djc, giampaolo.rodola, stutzbach
Priority: normal Keywords:

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:54adminsetgithub: 51390
2010-09-03 00:50:09benjamin.petersonsetstatus: open -> closed
resolution: rejected
messages: + msg115410
2010-09-02 08:57:18giampaolo.rodolasetnosy: + giampaolo.rodola
messages: + msg115362
2010-09-02 02:26:16stutzbachsetmessages: + msg115356
2010-09-02 01:37:24benjamin.petersonsetmessages: + msg115355
2010-09-02 01:35:34stutzbachsetmessages: + msg115353
2010-09-02 01:30:01benjamin.petersonsetmessages: + msg115352
2010-08-31 21:53:22stutzbachsetmessages: + msg115278
stage: needs patch
2010-08-03 16:50:00BreamoreBoysetnosy: + BreamoreBoy

messages: + msg112627
versions: - Python 2.7
2010-08-03 14:17:02djcsetnosy: + djc
2009-10-15 15:39:13georg.brandlsetassignee: benjamin.peterson

nosy: + benjamin.peterson
2009-10-15 15:28:32stutzbachcreate