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 fix_future.py removes __future__ imports, but should it?
Type: Stage:
Components: 2to3 (2.x to 3.x conversion tool) Versions: Python 3.1, Python 3.2
process
Status: closed Resolution: works for me
Dependencies: Superseder:
Assigned To: Nosy List: barry, benjamin.peterson, eric.araujo
Priority: normal Keywords:

Created on 2010-04-23 12:31 by barry, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (7)
msg104008 - (view) Author: Barry A. Warsaw (barry) * (Python committer) Date: 2010-04-23 12:31
Lines such as the following are removed by fix_future.py in 2to3

from __future__ import absolute_import, unicode_literals

I think this is unnecessary and I have a case where it causes problems.  It's unnecessary because this import is essentially a no-op in Python 3, so it does no harm, and serves no actual useful purpose to remove.  It causes harm because of a common idiom in doctest setups:

def setup(testobj):
    """Test setup."""
    # Make sure future statements in our doctests match the Python code.
    testobj.globs['absolute_import'] = absolute_import
    testobj.globs['unicode_literals'] = unicode_literals

fix_future.py removes the import so these cause NameErrors.  Sure, I can wrap them in try/excepts, but still what's the point of fix_future?
msg104049 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2010-04-23 20:39
You can just turn off fix_future with -x future.
msg104104 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2010-04-24 17:10
I think the unnecessary removal of __future__ imports but consistent with the idea that Python 3 is a new start, a blank sheet, and we don’t mention every novelty since previous versions.
msg104105 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2010-04-24 17:12
s/but/is/
msg104123 - (view) Author: Barry A. Warsaw (barry) * (Python committer) Date: 2010-04-24 19:27
Removing __future__ as part of explicit command line execution of 2to3 makes some sense, but I wonder if 2to3 is used more often automatically (e.g. via Distribute) where it's at best unhelpful.  2to3 is all about making it easy to port code from Python 2 to 3, and this particular transformation makes it (albeit, slightly so) harder.

A different idea would be to add a comment before the future import indicating its uselessness, but not removing it.  OTOH, I would also be happy with a better way to just disable it in a setup.py (e.g. by passing the -x flag in somehow).
msg104124 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2010-04-24 19:29
2010/4/24 Barry A. Warsaw <report@bugs.python.org>:
>
> Barry A. Warsaw <barry@python.org> added the comment:
>
> Removing __future__ as part of explicit command line execution of 2to3 makes some sense, but I wonder if 2to3 is used more often automatically (e.g. via Distribute) where it's at best unhelpful.  2to3 is all about making it easy to port code from Python 2 to 3, and this particular transformation makes it (albeit, slightly so) harder.

It's also designed to be easily customizable.

>
> A different idea would be to add a comment before the future import indicating its uselessness, but not removing it.  OTOH, I would also be happy with a better way to just disable it in a setup.py (e.g. by passing the -x flag in somehow).

I'm not sure we should get into the habit of telling people that their
code is useless. :)

I'll just close this as won't fix.
msg104125 - (view) Author: Barry A. Warsaw (barry) * (Python committer) Date: 2010-04-24 19:34
Since the workaround is easy enough, I won't push for this.  I still think it's an unhelpful transformation.
History
Date User Action Args
2022-04-11 14:57:00adminsetgithub: 52751
2010-04-24 19:34:21barrysetmessages: + msg104125
2010-04-24 19:30:38benjamin.petersonsetstatus: open -> closed
resolution: works for me
2010-04-24 19:29:26benjamin.petersonsetmessages: + msg104124
title: 2to3 fix_future.py removes __future__ imports, but should it? -> 2to3 fix_future.py removes __future__ imports, but should it?
2010-04-24 19:27:33barrysetmessages: + msg104123
2010-04-24 17:12:07eric.araujosetmessages: + msg104105
title: 2to3 fix_future.py removes __future__ imports, but should it? -> 2to3 fix_future.py removes __future__ imports, but should it?
2010-04-24 17:10:44eric.araujosetnosy: + eric.araujo
messages: + msg104104
2010-04-23 20:39:18benjamin.petersonsetnosy: + benjamin.peterson
messages: + msg104049
2010-04-23 12:31:14barrycreate