[Python-checkins] r61664 - in sandbox/trunk/2to3/lib2to3: fixes/fix_future.py fixes/fix_itertools_imports.py tests/test_fixers.py
david.wolever
python-checkins at python.org
Thu Mar 20 04:32:40 CET 2008
Author: david.wolever
Date: Thu Mar 20 04:32:40 2008
New Revision: 61664
Modified:
sandbox/trunk/2to3/lib2to3/fixes/fix_future.py
sandbox/trunk/2to3/lib2to3/fixes/fix_itertools_imports.py
sandbox/trunk/2to3/lib2to3/tests/test_fixers.py
Log:
Fixes #2428 -- comments are no longer eatten by __future__ fixer.
Modified: sandbox/trunk/2to3/lib2to3/fixes/fix_future.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixes/fix_future.py (original)
+++ sandbox/trunk/2to3/lib2to3/fixes/fix_future.py Thu Mar 20 04:32:40 2008
@@ -15,4 +15,6 @@
run_order = 10
def transform(self, node, results):
- return BlankLine()
+ new = BlankLine()
+ new.prefix = node.get_prefix()
+ return new
Modified: sandbox/trunk/2to3/lib2to3/fixes/fix_itertools_imports.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixes/fix_itertools_imports.py (original)
+++ sandbox/trunk/2to3/lib2to3/fixes/fix_itertools_imports.py Thu Mar 20 04:32:40 2008
@@ -36,6 +36,8 @@
# If there is nothing left, return a blank line
if not (imports.children or getattr(imports, 'value', None)):
- node = BlankLine()
-
- return node
+ new = BlankLine()
+ new.prefix = node.get_prefix()
+ else:
+ new = node
+ return new
Modified: sandbox/trunk/2to3/lib2to3/tests/test_fixers.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/tests/test_fixers.py (original)
+++ sandbox/trunk/2to3/lib2to3/tests/test_fixers.py Thu Mar 20 04:32:40 2008
@@ -2955,10 +2955,17 @@
a = """"""
self.check(b, a)
+ b = """# comment\nfrom __future__ import braces"""
+ a = """# comment\n"""
+ self.check(b, a)
+
+ b = """from __future__ import braces\n# comment"""
+ a = """\n# comment"""
+ self.check(b, a)
+
def test_run_order(self):
self.assert_runs_after('print')
-
class Test_itertools(FixerTestCase):
fixer = "itertools"
@@ -3019,6 +3026,11 @@
a = "from itertools import bar, foo"
self.check(b, a)
+ def test_comments(self):
+ b = "#foo\nfrom itertools import imap, izip"
+ a = "#foo\n"
+ self.check(b, a)
+
def test_none(self):
b = "from itertools import imap, izip"
a = ""
More information about the Python-checkins
mailing list