diff options
Diffstat (limited to 'Lib/lib2to3/fixes/fix_itertools_imports.py')
-rw-r--r-- | Lib/lib2to3/fixes/fix_itertools_imports.py | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/Lib/lib2to3/fixes/fix_itertools_imports.py b/Lib/lib2to3/fixes/fix_itertools_imports.py index 0faa4ea..d5876a5 100644 --- a/Lib/lib2to3/fixes/fix_itertools_imports.py +++ b/Lib/lib2to3/fixes/fix_itertools_imports.py @@ -17,6 +17,9 @@ class FixItertoolsImports(basefix.BaseFix): # 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 @@ class FixItertoolsImports(basefix.BaseFix): 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 |