Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update imp to importlib for py3 #574

Merged
merged 3 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion docs/other/auto2to3.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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