Commit 7a3056fa authored by Berker Peksag's avatar Berker Peksag Committed by GitHub

bpo-21446: Update reload fixer to use importlib (GH-8391)

parent d04f46c5
...@@ -385,7 +385,7 @@ and off individually. They are described here in more detail. ...@@ -385,7 +385,7 @@ and off individually. They are described here in more detail.
.. 2to3fixer:: reload .. 2to3fixer:: reload
Converts :func:`reload` to :func:`imp.reload`. Converts :func:`reload` to :func:`importlib.reload`.
.. 2to3fixer:: renames .. 2to3fixer:: renames
......
"""Fixer for reload(). """Fixer for reload().
reload(s) -> imp.reload(s)""" reload(s) -> importlib.reload(s)"""
# Local imports # Local imports
from .. import fixer_base from .. import fixer_base
...@@ -32,7 +32,7 @@ class FixReload(fixer_base.BaseFix): ...@@ -32,7 +32,7 @@ class FixReload(fixer_base.BaseFix):
if (obj.type == self.syms.argument and if (obj.type == self.syms.argument and
obj.children[0].value == '**'): obj.children[0].value == '**'):
return # Make no change. return # Make no change.
names = ('imp', 'reload') names = ('importlib', 'reload')
new = ImportAndCall(node, results, names) new = ImportAndCall(node, results, names)
touch_import(None, 'imp', node) touch_import(None, 'importlib', node)
return new return new
...@@ -290,30 +290,30 @@ class Test_reload(FixerTestCase): ...@@ -290,30 +290,30 @@ class Test_reload(FixerTestCase):
def test(self): def test(self):
b = """reload(a)""" b = """reload(a)"""
a = """import imp\nimp.reload(a)""" a = """import importlib\nimportlib.reload(a)"""
self.check(b, a) self.check(b, a)
def test_comment(self): def test_comment(self):
b = """reload( a ) # comment""" b = """reload( a ) # comment"""
a = """import imp\nimp.reload( a ) # comment""" a = """import importlib\nimportlib.reload( a ) # comment"""
self.check(b, a) self.check(b, a)
# PEP 8 comments # PEP 8 comments
b = """reload( a ) # comment""" b = """reload( a ) # comment"""
a = """import imp\nimp.reload( a ) # comment""" a = """import importlib\nimportlib.reload( a ) # comment"""
self.check(b, a) self.check(b, a)
def test_space(self): def test_space(self):
b = """reload( a )""" b = """reload( a )"""
a = """import imp\nimp.reload( a )""" a = """import importlib\nimportlib.reload( a )"""
self.check(b, a) self.check(b, a)
b = """reload( a)""" b = """reload( a)"""
a = """import imp\nimp.reload( a)""" a = """import importlib\nimportlib.reload( a)"""
self.check(b, a) self.check(b, a)
b = """reload(a )""" b = """reload(a )"""
a = """import imp\nimp.reload(a )""" a = """import importlib\nimportlib.reload(a )"""
self.check(b, a) self.check(b, a)
def test_unchanged(self): def test_unchanged(self):
......
The :2to3fixer:`reload` fixer now uses :func:`importlib.reload` instead of
deprecated :func:`imp.reload`.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment