Skip to content

Commit ba1cc50

Browse files
authored
Merge pull request #632 from nsoranzo/python312-imp-module_past
Python 3.12 support
2 parents a6222d2 + 9ef05b3 commit ba1cc50

File tree

12 files changed

+152
-220
lines changed

12 files changed

+152
-220
lines changed

Diff for: setup.py

+5
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@
103103
"Programming Language :: Python :: 3.5",
104104
"Programming Language :: Python :: 3.6",
105105
"Programming Language :: Python :: 3.7",
106+
"Programming Language :: Python :: 3.8",
107+
"Programming Language :: Python :: 3.9",
108+
"Programming Language :: Python :: 3.10",
109+
"Programming Language :: Python :: 3.11",
110+
"Programming Language :: Python :: 3.12",
106111
"License :: OSI Approved",
107112
"License :: OSI Approved :: MIT License",
108113
"Development Status :: 4 - Beta",

Diff for: src/future/backports/test/support.py

-35
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@
2828
# import collections.abc # not present on Py2.7
2929
import re
3030
import subprocess
31-
try:
32-
from imp import cache_from_source
33-
except ImportError:
34-
from importlib.util import cache_from_source
3531
import time
3632
try:
3733
import sysconfig
@@ -344,37 +340,6 @@ def rmtree(path):
344340
if error.errno != errno.ENOENT:
345341
raise
346342

347-
def make_legacy_pyc(source):
348-
"""Move a PEP 3147 pyc/pyo file to its legacy pyc/pyo location.
349-
350-
The choice of .pyc or .pyo extension is done based on the __debug__ flag
351-
value.
352-
353-
:param source: The file system path to the source file. The source file
354-
does not need to exist, however the PEP 3147 pyc file must exist.
355-
:return: The file system path to the legacy pyc file.
356-
"""
357-
pyc_file = cache_from_source(source)
358-
up_one = os.path.dirname(os.path.abspath(source))
359-
legacy_pyc = os.path.join(up_one, source + ('c' if __debug__ else 'o'))
360-
os.rename(pyc_file, legacy_pyc)
361-
return legacy_pyc
362-
363-
def forget(modname):
364-
"""'Forget' a module was ever imported.
365-
366-
This removes the module from sys.modules and deletes any PEP 3147 or
367-
legacy .pyc and .pyo files.
368-
"""
369-
unload(modname)
370-
for dirname in sys.path:
371-
source = os.path.join(dirname, modname + '.py')
372-
# It doesn't matter if they exist or not, unlink all possible
373-
# combinations of PEP 3147 and legacy pyc and pyo files.
374-
unlink(source + 'c')
375-
unlink(source + 'o')
376-
unlink(cache_from_source(source, debug_override=True))
377-
unlink(cache_from_source(source, debug_override=False))
378343

379344
# On some platforms, should not run gui test even if it is allowed
380345
# in `use_resources'.

Diff for: src/future/moves/test/support.py

+9
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
from __future__ import absolute_import
2+
3+
import sys
4+
25
from future.standard_library import suspend_hooks
36
from future.utils import PY3
47

58
if PY3:
69
from test.support import *
10+
if sys.version_info[:2] >= (3, 10):
11+
from test.support.os_helper import (
12+
EnvironmentVarGuard,
13+
TESTFN,
14+
)
15+
from test.support.warnings_helper import check_warnings
716
else:
817
__future_module__ = True
918
with suspend_hooks():

Diff for: src/future/standard_library/__init__.py

+5-10
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,7 @@
6262

6363
import sys
6464
import logging
65-
try:
66-
import importlib
67-
except ImportError:
68-
import imp
6965
import contextlib
70-
import types
7166
import copy
7267
import os
7368

@@ -82,6 +77,9 @@
8277

8378
from future.utils import PY2, PY3
8479

80+
if PY2:
81+
import imp
82+
8583
# The modules that are defined under the same names on Py3 but with
8684
# different contents in a significant way (e.g. submodules) are:
8785
# pickle (fast one)
@@ -300,11 +298,8 @@ def _find_and_load_module(self, name, path=None):
300298
flog.debug('What to do here?')
301299

302300
name = bits[0]
303-
try:
304-
module_info = imp.find_module(name, path)
305-
return imp.load_module(name, *module_info)
306-
except AttributeError:
307-
return importlib.import_module(name, path)
301+
module_info = imp.find_module(name, path)
302+
return imp.load_module(name, *module_info)
308303

309304

310305
class hooks(object):

0 commit comments

Comments
 (0)