From 9f2a0fee45e68447265a8339a816773c3cf2e036 Mon Sep 17 00:00:00 2001 From: Martin Di Paola Date: Sun, 20 Feb 2022 23:18:20 +0000 Subject: [PATCH] Replace find_module with find_spec + exec_module find_module is deprecated and 3.10 was removed. The almost immediate replacement is call to find_spec to get a ModuleSpec and from there, access to its loader attribute to get a Loader. importlib's module_from_spec will create the Module and loader's exec_module will load it (execute it). For reference: - https://bugs.python.org/issue43540 --- byexample/init.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/byexample/init.py b/byexample/init.py index 24118c3d..119fa847 100644 --- a/byexample/init.py +++ b/byexample/init.py @@ -1,5 +1,6 @@ from __future__ import unicode_literals import sys, pkgutil, inspect, pprint, os, operator +import importlib.util from itertools import chain as chain_iters @@ -108,7 +109,9 @@ def load_modules(dirnames, cfg): clog().debug("From '%s' loading '%s'...", path, name) try: - module = importer.find_module(name).load_module(name) + spec = importer.find_spec(name) + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(module) except Exception as e: clog().info( "From '%s' loading '%s'...failed: %s", path, name, str(e)