Skip to content

Commit 6babd20

Browse files
authored
Merge pull request #574 from jccurtis/fix-importlib-deprecation
Update imp to importlib for py3
2 parents cd717be + 925039a commit 6babd20

File tree

5 files changed

+27
-14
lines changed

5 files changed

+27
-14
lines changed

docs/other/auto2to3.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@
1919
import argparse
2020
import os
2121
import sys
22-
import imp
22+
# imp was deprecated in python 3.6
23+
if sys.version_info >= (3, 6):
24+
import importlib as imp
25+
else:
26+
import imp
2327
import runpy
2428
from io import StringIO
2529
from pkgutil import ImpImporter, ImpLoader

src/future/standard_library/__init__.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@
6262

6363
import sys
6464
import logging
65+
# imp was deprecated in python 3.6
66+
if sys.version_info >= (3, 6):
67+
import importlib as imp
68+
else:
69+
import imp
6570
import contextlib
6671
import copy
6772
import os
@@ -77,9 +82,6 @@
7782

7883
from future.utils import PY2, PY3
7984

80-
if PY2:
81-
import imp
82-
8385
# The modules that are defined under the same names on Py3 but with
8486
# different contents in a significant way (e.g. submodules) are:
8587
# pickle (fast one)

src/past/builtins/misc.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
from __future__ import unicode_literals
22

33
import inspect
4+
import sys
45
import math
56
import numbers
67

78
from future.utils import PY2, PY3, exec_
89

10+
911
if PY2:
1012
from collections import Mapping
1113
else:
@@ -103,13 +105,12 @@ def oct(number):
103105
return '0' + builtins.oct(number)[2:]
104106

105107
raw_input = input
106-
107-
try:
108+
# imp was deprecated in python 3.6
109+
if sys.version_info >= (3, 6):
108110
from importlib import reload
109-
except ImportError:
111+
else:
110112
# for python2, python3 <= 3.4
111113
from imp import reload
112-
113114
unicode = str
114115
unichr = chr
115116
xrange = range

src/past/translation/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,14 @@
3232
Inspired by and based on ``uprefix`` by Vinay M. Sajip.
3333
"""
3434

35+
import sys
36+
# imp was deprecated in python 3.6
37+
if sys.version_info >= (3, 6):
38+
import importlib as imp
39+
else:
40+
import imp
3541
import logging
3642
import os
37-
import sys
3843
import copy
3944
from lib2to3.pgen2.parse import ParseError
4045
from lib2to3.refactor import RefactoringTool

tests/test_future/test_standard_library.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -447,11 +447,12 @@ def test_reload(self):
447447
"""
448448
reload has been moved to the imp module
449449
"""
450-
try:
451-
from importlib import reload
452-
except ImportError:
453-
from imp import reload
454-
reload(sys)
450+
# imp was deprecated in python 3.6
451+
if sys.version_info >= (3, 6):
452+
import importlib as imp
453+
else:
454+
import imp
455+
imp.reload(sys)
455456
self.assertTrue(True)
456457

457458
def test_install_aliases(self):

0 commit comments

Comments
 (0)