Skip to content

Commit a6222d2

Browse files
authored
Merge pull request #626 from odie5533/python312-imp-module
WIP Python 3.12 support for removal of imp module
2 parents 3dc7acc + 1901c1c commit a6222d2

File tree

7 files changed

+36
-13
lines changed

7 files changed

+36
-13
lines changed

build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ set -xuo pipefail
33

44
DOCKER_IMAGE=jmadler/python-future-builder
55
# XXX: TODO: Perhaps this version shouldn't be hardcoded
6-
version=0.18.3
6+
version=0.18.4
77

88
docker build . -t $DOCKER_IMAGE
99
docker push $DOCKER_IMAGE:latest

docs/whatsnew.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
What's New
44
**********
55

6+
What's new in version 0.18.4 (2023-10-10)
7+
=========================================
8+
This is a minor bug-fix release containing a number of fixes:
9+
10+
- Fix for Python 3.12's removal of the imp module
11+
612
What's new in version 0.18.3 (2023-01-13)
713
=========================================
814
This is a minor bug-fix release containing a number of fixes:

src/future/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
__copyright__ = 'Copyright 2013-2019 Python Charmers Pty Ltd'
8888
__ver_major__ = 0
8989
__ver_minor__ = 18
90-
__ver_patch__ = 3
90+
__ver_patch__ = 4
9191
__ver_sub__ = ''
9292
__version__ = "%d.%d.%d%s" % (__ver_major__, __ver_minor__,
9393
__ver_patch__, __ver_sub__)

src/future/backports/test/support.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@
2828
# import collections.abc # not present on Py2.7
2929
import re
3030
import subprocess
31-
import imp
31+
try:
32+
from imp import cache_from_source
33+
except ImportError:
34+
from importlib.util import cache_from_source
3235
import time
3336
try:
3437
import sysconfig
@@ -351,7 +354,7 @@ def make_legacy_pyc(source):
351354
does not need to exist, however the PEP 3147 pyc file must exist.
352355
:return: The file system path to the legacy pyc file.
353356
"""
354-
pyc_file = imp.cache_from_source(source)
357+
pyc_file = cache_from_source(source)
355358
up_one = os.path.dirname(os.path.abspath(source))
356359
legacy_pyc = os.path.join(up_one, source + ('c' if __debug__ else 'o'))
357360
os.rename(pyc_file, legacy_pyc)
@@ -370,8 +373,8 @@ def forget(modname):
370373
# combinations of PEP 3147 and legacy pyc and pyo files.
371374
unlink(source + 'c')
372375
unlink(source + 'o')
373-
unlink(imp.cache_from_source(source, debug_override=True))
374-
unlink(imp.cache_from_source(source, debug_override=False))
376+
unlink(cache_from_source(source, debug_override=True))
377+
unlink(cache_from_source(source, debug_override=False))
375378

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

src/future/standard_library/__init__.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,10 @@
6262

6363
import sys
6464
import logging
65-
import imp
65+
try:
66+
import importlib
67+
except ImportError:
68+
import imp
6669
import contextlib
6770
import types
6871
import copy
@@ -297,8 +300,11 @@ def _find_and_load_module(self, name, path=None):
297300
flog.debug('What to do here?')
298301

299302
name = bits[0]
300-
module_info = imp.find_module(name, path)
301-
return imp.load_module(name, *module_info)
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)
302308

303309

304310
class hooks(object):

src/past/translation/__init__.py

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

35-
import imp
35+
try:
36+
import imp
37+
except ImportError:
38+
import importlib
3639
import logging
3740
import marshal
3841
import os

tests/test_future/test_standard_library.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -447,9 +447,14 @@ def test_reload(self):
447447
"""
448448
reload has been moved to the imp module
449449
"""
450-
import imp
451-
imp.reload(imp)
452-
self.assertTrue(True)
450+
try:
451+
import imp
452+
imp.reload(imp)
453+
self.assertTrue(True)
454+
except ImportError:
455+
import importlib
456+
importlib.reload(importlib)
457+
self.assertTrue(True)
453458

454459
def test_install_aliases(self):
455460
"""

0 commit comments

Comments
 (0)