Repository: trentm/python-markdown2 (language: python)

Issue:
Replace deprecated imp module with importlib


This project's tests uses the [`imp` module](https://docs.python.org/3/library/imp.html) which has been deprecated since Python 3.4 and removed in 3.12:

* Raised `PendingDeprecationWarning` since [3.4 (2014)](https://github.com/python/cpython/commit/e4f41deccf94ccc798b1eb1f44657ade66669a60)
* Raised `DeprecationWarning` since [3.5 (2015)](https://github.com/python/cpython/commit/c0d91aff9a3b91307b26e8b7c34dfbf27bbdd43a)
* Updated `DeprecationWarning` to say removal in 3.12 since [3.10 (2021)](https://github.com/python/cpython/commit/dc6d3e1e4c0c1e4b2210edab8fb4762569dc2936)
* Removal planned for [3.12](https://github.com/python/cpython/issues/98040) [(2023)](https://github.com/python/cpython/pull/98573)

Python 3.12 is [set for release on 2023-10-02](https://devguide.python.org/versions/) and this library is one of the [top 5,000 most-downloaded from PyPI](https://hugovk.github.io/top-pypi-packages/).

Please could you upgrade to use `importlib`? The [`imp` docs](https://docs.python.org/3.11/library/imp.html) have suggestions on what to use to replace each function and constant.




Discussion / hints:

Fix patch:
diff --git a/CHANGES.md b/CHANGES.md
index c6b1df5e..70518201 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -7,6 +7,7 @@
 - [pull #502] Replace deprecated `optparse` with `argparse`
 - [pull #506] Fix `_uniform_outdent` failing with empty strings (issue #505)
 - [pull #509] Fix HTML elements not unhashing correctly (issue 508)
+- [pull #511] Remove deprecated `imp` module (issue #510)
 
 
 ## python-markdown2 2.4.8


Test patch:
diff --git a/test/testlib.py b/test/testlib.py
index 2c345573..c6244dc4 100644
--- a/test/testlib.py
+++ b/test/testlib.py
@@ -54,14 +54,14 @@
 
 
 import os
-from os.path import join, basename, dirname, abspath, splitext, \
+from os.path import join, basename, abspath, splitext, \
                     isfile, isdir, normpath, exists
 import sys
 import getopt
 import glob
 import time
 import unittest
-import imp
+import importlib
 import logging
 import textwrap
 import traceback
@@ -234,13 +234,12 @@ def testmods_from_testdir(testdir):
         testmod_name = splitext(basename(testmod_path))[0]
         log.debug("import test module '%s'", testmod_path)
         try:
-            iinfo = imp.find_module(testmod_name, [dirname(testmod_path)])
             testabsdir = abspath(testdir)
             sys.path.insert(0, testabsdir)
             old_dir = os.getcwd()
             os.chdir(testdir)
             try:
-                testmod = imp.load_module(testmod_name, *iinfo)
+                testmod = importlib.import_module(testmod_name)
             finally:
                 os.chdir(old_dir)
                 sys.path.remove(testabsdir)