Skip to content

Commit 947cb2d

Browse files
committed
Initial attempt at fixing futurize -d
1 parent 132e6c5 commit 947cb2d

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

libfuturize/fixes/fix_absolute_import.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77
If spam is being imported from the local directory, this import:
88
from spam import eggs
99
becomes:
10+
from __future__ import absolute_import
1011
from .spam import eggs
1112
1213
and this import:
1314
import spam
1415
becomes:
16+
from __future__ import absolute_import
1517
from . import spam
1618
"""
1719

libfuturize/main.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def main(args=None):
101101
parser.add_option("-a", "--all-imports", action="store_true",
102102
help="Add all __future__ and future imports to each module")
103103
parser.add_option("-d", "--doctests_only", action="store_true",
104-
help="Fix up doctests only")
104+
help="Fix up doctests instead of regular code")
105105
parser.add_option("-1", "--stage1", action="store_true",
106106
help="Modernize Python 2 code only; no compatibility with Python 3 (or dependency on ``future``)")
107107
parser.add_option("-2", "--stage2", action="store_true",
@@ -275,6 +275,18 @@ def main(args=None):
275275
'output_dir': options.output_dir,
276276
'input_base_dir': input_base_dir,
277277
}
278+
# refactor_doctest() in lib2to3/refactor.py has an assert statement
279+
# that dies if it sees a __future__ import. So strip these out.
280+
if options.doctests_only:
281+
print('Warning: due to a limitation in lib2to3, doctests will not '
282+
'include __future__ imports (issue #103)',
283+
file=sys.stderr)
284+
fixer_names -= set(['libfuturize.fixes.fix_print_with_import',
285+
'libfuturize.fixes.fix_absolute_import',
286+
'libfuturize.fixes.fix_division_safe'])
287+
fixer_names |= set(['lib2to3.fixes.fix_print',
288+
'lib2to3.fixes.fix_import'])
289+
278290
rt = StdoutRefactoringTool(
279291
sorted(fixer_names), flags, sorted(explicit),
280292
options.nobackups, not options.no_diffs,

0 commit comments

Comments
 (0)