[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: [PATCH] Avoid DeprecationWarning on make check with Python >= 3.5

From: Daniel Shahaf <d.s_at_daniel.shahaf.name>
Date: Fri, 3 Jan 2020 16:22:16 +0000

Yasuhito FUTATSUKI wrote on Fri, Jan 03, 2020 at 05:34:48 +0900:
> +++ build/run_tests.py (working copy)
> @@ -64,6 +64,11 @@
> +if sys.version_info < (3, 5):
> + import imp
> +else:
> + import importlib.util

Add a comment here explaining the reason for this? E.g., —

    # The imp module is deprecated since Python 3.4; the replacement we use,
    # module_from_spec(), is available since Python 3.5.

> @@ -821,10 +826,15 @@
> if sys.version_info < (3, 0):
> prog_mod = imp.load_module(progbase[:-3], open(progabs, 'r'), progabs,
> ('.py', 'U', imp.PY_SOURCE))
> - else:
> + elif sys.version_info < (3, 5):
> prog_mod = imp.load_module(progbase[:-3],
> open(progabs, 'r', encoding="utf-8"),
> progabs, ('.py', 'U', imp.PY_SOURCE))
> + else:
> + spec = importlib.util.spec_from_file_location(progbase[:-3], progabs)
> + prog_mod = importlib.util.module_from_spec(spec)
> + sys.modules[progbase[:-3]] = prog_mod
> + spec.loader.exec_module(prog_mod)

Looks good to me. I looked at the docstrings of the called functions and
I don't see any reason not to use the code example as-is.

All tests pass, Python 3.5.3 on Linux.

Cheers,

Daniel
Received on 2020-01-03 17:22:25 CET

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.