diff -r 8c5b845c14fc lib2to3/fixes/fix_itertools.py --- a/lib2to3/fixes/fix_itertools.py Wed Feb 24 02:21:34 2010 +0000 +++ b/lib2to3/fixes/fix_itertools.py Wed Aug 10 23:01:24 2011 -0500 @@ -16,9 +16,9 @@ PATTERN = """ power< it='itertools' trailer< - dot='.' func=%(it_funcs)s > trailer< '(' [any] ')' > > + dot='.' func=%(it_funcs)s > trailer< '(' [any] ')' > any* > | - power< func=%(it_funcs)s trailer< '(' [any] ')' > > + power< func=%(it_funcs)s trailer< '(' [any] ')' > any* > """ %(locals()) # Needs to be run after fix_(map|zip|filter) diff -r 8c5b845c14fc lib2to3/fixes/fix_next.py --- a/lib2to3/fixes/fix_next.py Wed Feb 24 02:21:34 2010 +0000 +++ b/lib2to3/fixes/fix_next.py Wed Aug 10 23:01:24 2011 -0500 @@ -6,6 +6,7 @@ # - "with" statement targets aren't checked # Local imports +from .. import pytree from ..pgen2 import token from ..pygram import python_symbols as syms from .. import fixer_base @@ -55,6 +56,8 @@ else: base = [n.clone() for n in base] base[0].prefix = u"" + base = [pytree.Node(syms.power, base)] + base[0].prefix = u"" node.replace(Call(Name(u"next", prefix=node.prefix), base)) elif name: n = Name(u"__next__", prefix=name.prefix) diff -r 8c5b845c14fc lib2to3/tests/test_fixers.py --- a/lib2to3/tests/test_fixers.py Wed Feb 24 02:21:34 2010 +0000 +++ b/lib2to3/tests/test_fixers.py Wed Aug 10 23:01:24 2011 -0500 @@ -3600,6 +3600,19 @@ def test_run_order(self): self.assert_runs_after('map', 'zip', 'filter') + def test_chained_calls(self): + b = """%s(f, a).next()""" + a = """%s(f, a).next()""" + self.checkall(b, a) + + b = """%s(f, a).foo()""" + a = """%s(f, a).foo()""" + self.checkall(b, a) + + b = """%s(f, a).foo().bar()""" + a = """%s(f, a).foo().bar()""" + self.checkall(b, a) + class Test_itertools_imports(FixerTestCase): fixer = 'itertools_imports'