[reportlab-users] Deprecated warning on Python 3.10

Robin Becker robin at reportlab.com
Fri Sep 29 11:42:52 EDT 2023


Hi Frank,

sorry to have missed the various attempts to excite action on this.

I am testing reportlab with 3.12.0rc3; running all of our tests did not cause an issue with this particular code. 
However, perhaps that just because the try is hiding it.

I will take a look at the case ~/.reportlab_mods is needed. I tried your changes, but they don't seem to fix a failure.

I will have to figure out what the modern way to import a source file directly is.

I made a change in a commit today. Can you try and see if this works for pytest? A remaining issue exists in utils.py, 
but that is now rarely used and broken in python 3.
--
Robin Becker

On 28/09/2023 10:26, Frank Epperlein wrote:
> 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
> _______________________________________________
> reportlab-users mailing list
> reportlab-users at lists2.reportlab.com
> https://pairlist2.pair.net/mailman/listinfo/reportlab-users

-- 
Robin Becker



More information about the reportlab-users mailing list