[Python-checkins] r61824 - in sandbox/trunk/2to3/lib2to3: fixes/fix_itertools_imports.py tests/test_fixers.py
david.wolever
python-checkins at python.org
Mon Mar 24 01:30:24 CET 2008
Author: david.wolever
Date: Mon Mar 24 01:30:24 2008
New Revision: 61824
Modified:
sandbox/trunk/2to3/lib2to3/fixes/fix_itertools_imports.py
sandbox/trunk/2to3/lib2to3/tests/test_fixers.py
Log:
Fixed a bug where 'from itertools import izip' would return 'from itertools import'
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 Mon Mar 24 01:30:24 2008
@@ -17,6 +17,9 @@
# Handle 'import ... as ...'
continue
if child.value in ('imap', 'izip', 'ifilter'):
+ # The value must be set to none in case child == import,
+ # so that the test for empty imports will work out
+ child.value = None
child.remove()
elif child.value == 'ifilterfalse':
node.changed()
@@ -34,10 +37,9 @@
if unicode(children[-1]) == ',':
children[-1].remove()
- # If there is nothing left, return a blank line
+ # If there are no imports left, just get rid of the entire statement
if not (imports.children or getattr(imports, 'value', None)):
- new = BlankLine()
- new.prefix = node.get_prefix()
- else:
- new = node
- return new
+ p = node.get_prefix()
+ node = BlankLine()
+ node.prefix = p
+ return node
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 Mon Mar 24 01:30:24 2008
@@ -3036,6 +3036,10 @@
a = ""
self.check(b, a)
+ b = "from itertools import izip"
+ a = ""
+ self.check(b, a)
+
def test_import_as(self):
b = "from itertools import izip, bar as bang, imap"
a = "from itertools import bar as bang"
More information about the Python-checkins
mailing list