Issue 8505: 2to3 fix_future.py removes future imports, but should it? (original) (raw)

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:00 admin set github: 52751
2010-04-24 19:34:21 barry set messages: +
2010-04-24 19:30:38 benjamin.peterson set status: open -> closedresolution: works for me
2010-04-24 19:29:26 benjamin.peterson set messages: + 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:33 barry set messages: +
2010-04-24 17:12:07 eric.araujo set messages: + 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:44 eric.araujo set nosy: + eric.araujomessages: +
2010-04-23 20:39:18 benjamin.peterson set nosy: + benjamin.petersonmessages: +
2010-04-23 12:31:14 barry create