diff -r 8dde150437cc Doc/library/2to3.rst --- a/Doc/library/2to3.rst Tue Jun 23 15:10:21 2015 -0400 +++ b/Doc/library/2to3.rst Wed Jun 24 17:14:41 2015 +1200 @@ -233,6 +233,11 @@ Removes ``from __future__ import new_feature`` statements. +.. 2to3fixer:: future_builtins + + Replaces ``from future_builtins import new_builtin`` statements by a blank + line or ``pass`` if inside a code block. This fixer is optional. + .. 2to3fixer:: getcwdu Renames :func:`os.getcwdu` to :func:`os.getcwd`. diff -r 8dde150437cc Lib/lib2to3/fixes/fix_future_builtins.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/lib2to3/fixes/fix_future_builtins.py Wed Jun 24 17:14:41 2015 +1200 @@ -0,0 +1,26 @@ +"""Remove future_builtins imports. + +from future_builtins import foo is replaced either with an empty line or a +'pass' (if inside a code-block). +""" +# Author: Milan Oberkirch + +# Local imports +from .. import fixer_base +from ..fixer_util import BlankLine, Name, Call + +class FixFutureBuiltins(fixer_base.BaseFix): + BM_compatible = True + + PATTERN = """import_from< 'from' module_name="future_builtins" 'import' any >""" + + # Some things check for the import, so do this at the end + run_order = 10 + # Do not run this by default. + explicit = True + + def transform(self, node, results): + # Replace import by pass if it was inside another codeblock. + new = Name('pass') if node.depth() > 2 else BlankLine() + new.prefix = node.prefix + return new