diff --git a/Doc/library/2to3.rst b/Doc/library/2to3.rst --- a/Doc/library/2to3.rst +++ b/Doc/library/2to3.rst @@ -372,17 +372,21 @@ and off individually. They are describe Converts :func:`raw_input` to :func:`input`. .. 2to3fixer:: reduce Handles the move of :func:`reduce` to :func:`functools.reduce`. .. 2to3fixer:: reload - Converts :func:`reload` to :func:`imp.reload`. + Converts :func:`reload` to :func:`importlib.reload`. + + .. versionchanged:: 3.5 + Updated to use :func:`importlib.reload` instead of deprecated + :func:`imp.reload`. .. 2to3fixer:: renames Changes :data:`sys.maxint` to :data:`sys.maxsize`. .. 2to3fixer:: repr Replaces backtick repr with the :func:`repr` function. diff --git a/Lib/lib2to3/fixes/fix_reload.py b/Lib/lib2to3/fixes/fix_reload.py --- a/Lib/lib2to3/fixes/fix_reload.py +++ b/Lib/lib2to3/fixes/fix_reload.py @@ -1,11 +1,11 @@ """Fixer for reload(). -reload(s) -> imp.reload(s)""" +reload(s) -> importlib.reload(s)""" # Local imports from .. import fixer_base from ..fixer_util import ImportAndCall, touch_import class FixReload(fixer_base.BaseFix): BM_compatible = True @@ -17,12 +17,12 @@ class FixReload(fixer_base.BaseFix): ( not(arglist | argument) any ','> ) rpar=')' > after=any* > """ def transform(self, node, results): - names = ('imp', 'reload') + names = ('importlib', 'reload') new = ImportAndCall(node, results, names) - touch_import(None, 'imp', node) + touch_import(None, 'importlib', node) return new diff --git a/Lib/lib2to3/tests/test_fixers.py b/Lib/lib2to3/tests/test_fixers.py --- a/Lib/lib2to3/tests/test_fixers.py +++ b/Lib/lib2to3/tests/test_fixers.py @@ -282,40 +282,40 @@ class Test_apply(FixerTestCase): b = """f(*args, **kwds)""" self.check(a, b) class Test_reload(FixerTestCase): fixer = "reload" def test(self): b = """reload(a)""" - a = """import imp\nimp.reload(a)""" + a = """import importlib\nimportlib.reload(a)""" self.check(b, a) def test_comment(self): b = """reload( a ) # comment""" - a = """import imp\nimp.reload( a ) # comment""" + a = """import importlib\nimportlib.reload( a ) # comment""" self.check(b, a) # PEP 8 comments b = """reload( a ) # comment""" - a = """import imp\nimp.reload( a ) # comment""" + a = """import importlib\nimportlib.reload( a ) # comment""" self.check(b, a) def test_space(self): b = """reload( a )""" - a = """import imp\nimp.reload( a )""" + a = """import importlib\nimportlib.reload( a )""" self.check(b, a) b = """reload( a)""" - a = """import imp\nimp.reload( a)""" + a = """import importlib\nimportlib.reload( a)""" self.check(b, a) b = """reload(a )""" - a = """import imp\nimp.reload(a )""" + a = """import importlib\nimportlib.reload(a )""" self.check(b, a) def test_unchanged(self): s = """reload(a=1)""" self.unchanged(s) s = """reload(f, g)""" self.unchanged(s)