[Python-checkins] bpo-21446: Update reload fixer to use importlib (GH-8391)

Berker Peksag webhook-mailer at python.org
Mon Jul 23 04:11:33 EDT 2018


https://github.com/python/cpython/commit/05a72f15f76301c505a91728f0818b421fddd290
commit: 05a72f15f76301c505a91728f0818b421fddd290
branch: 3.7
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: Berker Peksag <berker.peksag at gmail.com>
date: 2018-07-23T11:11:22+03:00
summary:

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

(cherry picked from commit 7a3056fa7dd1223fe7112e53b236c43d71f33f64)

Co-authored-by: Berker Peksag <berker.peksag at gmail.com>

files:
A Misc/NEWS.d/next/Library/2018-07-22-09-05-01.bpo-21446.w6g7tn.rst
M Doc/library/2to3.rst
M Lib/lib2to3/fixes/fix_reload.py
M Lib/lib2to3/tests/test_fixers.py

diff --git a/Doc/library/2to3.rst b/Doc/library/2to3.rst
index deb5e10f6ef7..fa4b0a964553 100644
--- a/Doc/library/2to3.rst
+++ b/Doc/library/2to3.rst
@@ -385,7 +385,7 @@ and off individually.  They are described here in more detail.
 
 .. 2to3fixer:: reload
 
-   Converts :func:`reload` to :func:`imp.reload`.
+   Converts :func:`reload` to :func:`importlib.reload`.
 
 .. 2to3fixer:: renames
 
diff --git a/Lib/lib2to3/fixes/fix_reload.py b/Lib/lib2to3/fixes/fix_reload.py
index 5bec7d536382..6c7fbbd3be3f 100644
--- a/Lib/lib2to3/fixes/fix_reload.py
+++ b/Lib/lib2to3/fixes/fix_reload.py
@@ -1,6 +1,6 @@
 """Fixer for reload().
 
-reload(s) -> imp.reload(s)"""
+reload(s) -> importlib.reload(s)"""
 
 # Local imports
 from .. import fixer_base
@@ -32,7 +32,7 @@ def transform(self, node, results):
                 if (obj.type == self.syms.argument and
                     obj.children[0].value == '**'):
                     return  # Make no change.
-        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
index bfe7a23e7006..8cecf3cce61b 100644
--- a/Lib/lib2to3/tests/test_fixers.py
+++ b/Lib/lib2to3/tests/test_fixers.py
@@ -290,30 +290,30 @@ class Test_reload(FixerTestCase):
 
     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):
diff --git a/Misc/NEWS.d/next/Library/2018-07-22-09-05-01.bpo-21446.w6g7tn.rst b/Misc/NEWS.d/next/Library/2018-07-22-09-05-01.bpo-21446.w6g7tn.rst
new file mode 100644
index 000000000000..81da4a6b6a05
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2018-07-22-09-05-01.bpo-21446.w6g7tn.rst
@@ -0,0 +1,2 @@
+The :2to3fixer:`reload` fixer now uses :func:`importlib.reload` instead of
+deprecated :func:`imp.reload`.



More information about the Python-checkins mailing list