[reportlab-users] Deprecated warning on Python 3.10

Frank Epperlein frank+reportlab-users at epperle.in
Thu Sep 28 05:26:21 EDT 2023


Hi all,

I have a deprecation warning using Python 3.10+.

It was already mentioned by someone else over here: https://groups.google.com/g/reportlab-users/c/neGnrnTsZ9g

The warning I get when importing the module using Python3.10 is reproducible like this:

> $ python3.10 -Wall
> Python 3.10.12 (main, Jun 11 2023, 05:26:28) [GCC 11.4.0] on linux
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import reportlab
> <frozen importlib._bootstrap>:283: DeprecationWarning: the load_module() method is deprecated and slated for removal in Python 3.12; use exec_module() instead



Anyhow, now that I see it myself I made a small patch to update the relevant code part.

--- a/__init__.py
+++ b/__init__.py
@@ -5,7 +5,7 @@
 __version__=Version
 __date__='20230601'

-import sys, os
+import sys, os, importlib

 __min_python_version__ = (3,7)
 if sys.version_info< __min_python_version__:
@@ -18,10 +18,8 @@
     return -1 if a<b else (1 if a>b else 0)

 def _fake_import(fn,name):
-    from importlib import machinery
-    m = machinery.SourceFileLoader(name,fn)
     try:
-        sys.modules[name] = m.load_module(name)
+        sys.modules[name] = importlib.import_module(name)
     except FileNotFoundError:
         raise ImportError('file %s not found' % ascii(fn))


Please consider updating the package, before Python 3.12 gets released later this year.

Thank you

Frank Epperlein


More information about the reportlab-users mailing list