]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-21446: Update reload fixer to use importlib (GH-8391)
authorBerker Peksag <berker.peksag@gmail.com>
Mon, 23 Jul 2018 06:49:08 +0000 (09:49 +0300)
committerGitHub <noreply@github.com>
Mon, 23 Jul 2018 06:49:08 +0000 (09:49 +0300)
Doc/library/2to3.rst
Lib/lib2to3/fixes/fix_reload.py
Lib/lib2to3/tests/test_fixers.py
Misc/NEWS.d/next/Library/2018-07-22-09-05-01.bpo-21446.w6g7tn.rst [new file with mode: 0644]

index deb5e10f6ef7e98c23e9e646c7c6a7238a424051..fa4b0a9645531c4792d0116a226cd9ea13b8f83a 100644 (file)
@@ -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
 
index 5bec7d53638283611a725bf13c974f7e588334ac..6c7fbbd3be3fb3b8e70f5432643d328a1d1df381 100644 (file)
@@ -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 @@ class FixReload(fixer_base.BaseFix):
                 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
index bfe7a23e70068ab0569e5c3f3cc7738de8b8f411..8cecf3cce61b80175a38c74355bf53e2474b6c7e 100644 (file)
@@ -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 (file)
index 0000000..81da4a6
--- /dev/null
@@ -0,0 +1,2 @@
+The :2to3fixer:`reload` fixer now uses :func:`importlib.reload` instead of
+deprecated :func:`imp.reload`.