[Python-checkins] r61637 - in sandbox/trunk/2to3/lib2to3: fixes/fix_itertools.py tests/test_fixers.py
david.wolever
python-checkins at python.org
Wed Mar 19 21:37:17 CET 2008
Author: david.wolever
Date: Wed Mar 19 21:37:17 2008
New Revision: 61637
Modified:
sandbox/trunk/2to3/lib2to3/fixes/fix_itertools.py
sandbox/trunk/2to3/lib2to3/tests/test_fixers.py
Log:
Added a fixer for itertools imports (from itertools import imap, ifilterfalse --> from itertools import filterfalse)
Modified: sandbox/trunk/2to3/lib2to3/fixes/fix_itertools.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixes/fix_itertools.py (original)
+++ sandbox/trunk/2to3/lib2to3/fixes/fix_itertools.py Wed Mar 19 21:37:17 2008
@@ -1,6 +1,8 @@
""" Fixer for itertools.(imap|ifilter|izip) --> (map|filter|zip) and
itertools.ifilterfalse --> itertools.filterfalse (bugs 2360-2363)
+ imports from itertools are fixed in fix_itertools_import.py
+
If itertools is imported as something else (ie: import itertools as it;
it.izip(spam, eggs)) method calls will not get fixed.
"""
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 Wed Mar 19 21:37:17 2008
@@ -2984,6 +2984,51 @@
a = """ itertools.filterfalse(a, b)"""
self.check(b, a)
+class Test_itertools_imports(FixerTestCase):
+ fixer = 'itertools_imports'
+
+ def test_reduced(self):
+ b = "from itertools import imap, izip, foo"
+ a = "from itertools import foo"
+ self.check(b, a)
+
+ b = "from itertools import bar, imap, izip, foo"
+ a = "from itertools import bar, foo"
+ self.check(b, a)
+
+ def test_none(self):
+ b = "from itertools import imap, 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"
+ self.check(b, a)
+
+ s = "from itertools import bar as bang"
+ self.unchanged(s)
+
+ def test_ifilter(self):
+ b = "from itertools import ifilterfalse"
+ a = "from itertools import filterfalse"
+ self.check(b, a)
+
+ b = "from itertools import imap, ifilterfalse, foo"
+ a = "from itertools import filterfalse, foo"
+ self.check(b, a)
+
+ b = "from itertools import bar, ifilterfalse, foo"
+ a = "from itertools import bar, filterfalse, foo"
+ self.check(b, a)
+
+
+ def test_unchanged(self):
+ s = "from itertools import foo"
+ self.unchanged(s)
+
+
+
class Test_import(FixerTestCase):
fixer = "import"
More information about the Python-checkins
mailing list