Index: Doc/library/2to3.rst =================================================================== --- Doc/library/2to3.rst (revision 78510) +++ Doc/library/2to3.rst (working copy) @@ -135,6 +135,10 @@ :meth:`dict.values`. It also wraps existing usages of :meth:`dict.items`, :meth:`dict.keys`, and :meth:`dict.values` in a call to :class:`list`. +.. 2to3fixer:: file + + Converts :class:`file` to :func:`open`. + .. 2to3fixer:: except Converts ``except X, T`` to ``except X as T``. Index: Lib/lib2to3/tests/test_fixers.py =================================================================== --- Lib/lib2to3/tests/test_fixers.py (revision 78510) +++ Lib/lib2to3/tests/test_fixers.py (working copy) @@ -4285,3 +4285,12 @@ def test_bare_sequenceIncludes(self): s = "sequenceIncludes(x, y)" self.warns_unchanged(s, "You should use operator.contains here.") + + +class Test_file(FixerTestCase): + fixer = 'file' + + def test_file(self): + b = 'file(filename)' + a = 'open(filename)' + self.check(b, a) Index: Lib/lib2to3/fixes/fix_file.py =================================================================== --- Lib/lib2to3/fixes/fix_file.py (revision 0) +++ Lib/lib2to3/fixes/fix_file.py (revision 0) @@ -0,0 +1,14 @@ +"""Fixer for replacing builtin file(...) -> open(...)""" + +#from lib2to3 import fixer_base +#from lib2to3.fixer_util import Name, touch_import +from .. import fixer_base +from ..fixer_util import Name + + +class FixFile(fixer_base.BaseFix): + PATTERN = "power< name='file' trailer< '(' [any] ')' > any* >" + + def transform(self, node, results): + name = results['name'] + name.replace(Name('open', prefix=name.prefix)) Property changes on: Lib/lib2to3/fixes/fix_file.py ___________________________________________________________________ Added: svn:keywords + Id Added: svn:eol-style + native