Skip to content

Commit

Permalink
Merge pull request #574 from jccurtis/fix-importlib-deprecation
Browse files Browse the repository at this point in the history
Update imp to importlib for py3
  • Loading branch information
edschofield committed Feb 21, 2024
2 parents cd717be + 925039a commit 6babd20
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 14 deletions.
6 changes: 5 additions & 1 deletion docs/other/auto2to3.py
Expand Up @@ -19,7 +19,11 @@
import argparse
import os
import sys
import imp
# imp was deprecated in python 3.6
if sys.version_info >= (3, 6):
import importlib as imp
else:
import imp
import runpy
from io import StringIO
from pkgutil import ImpImporter, ImpLoader
Expand Down
8 changes: 5 additions & 3 deletions src/future/standard_library/__init__.py
Expand Up @@ -62,6 +62,11 @@

import sys
import logging
# imp was deprecated in python 3.6
if sys.version_info >= (3, 6):
import importlib as imp
else:
import imp
import contextlib
import copy
import os
Expand All @@ -77,9 +82,6 @@

from future.utils import PY2, PY3

if PY2:
import imp

# The modules that are defined under the same names on Py3 but with
# different contents in a significant way (e.g. submodules) are:
# pickle (fast one)
Expand Down
9 changes: 5 additions & 4 deletions src/past/builtins/misc.py
@@ -1,11 +1,13 @@
from __future__ import unicode_literals

import inspect
import sys
import math
import numbers

from future.utils import PY2, PY3, exec_


if PY2:
from collections import Mapping
else:
Expand Down Expand Up @@ -103,13 +105,12 @@ def oct(number):
return '0' + builtins.oct(number)[2:]

raw_input = input

try:
# imp was deprecated in python 3.6
if sys.version_info >= (3, 6):
from importlib import reload
except ImportError:
else:
# for python2, python3 <= 3.4
from imp import reload

unicode = str
unichr = chr
xrange = range
Expand Down
7 changes: 6 additions & 1 deletion src/past/translation/__init__.py
Expand Up @@ -32,9 +32,14 @@
Inspired by and based on ``uprefix`` by Vinay M. Sajip.
"""

import sys
# imp was deprecated in python 3.6
if sys.version_info >= (3, 6):
import importlib as imp
else:
import imp
import logging
import os
import sys
import copy
from lib2to3.pgen2.parse import ParseError
from lib2to3.refactor import RefactoringTool
Expand Down
11 changes: 6 additions & 5 deletions tests/test_future/test_standard_library.py
Expand Up @@ -447,11 +447,12 @@ def test_reload(self):
"""
reload has been moved to the imp module
"""
try:
from importlib import reload
except ImportError:
from imp import reload
reload(sys)
# imp was deprecated in python 3.6
if sys.version_info >= (3, 6):
import importlib as imp
else:
import imp
imp.reload(sys)
self.assertTrue(True)

def test_install_aliases(self):
Expand Down

0 comments on commit 6babd20

Please sign in to comment.