From 9d7841e3d4f7dff741c73ea5e63348f85919ff16 Mon Sep 17 00:00:00 2001 From: Tobias Ahrens Date: Wed, 4 Oct 2023 11:27:37 +0200 Subject: [PATCH] Replace deprecated find_module with find_spec (importlib) find_module was deprecated with python 3.4 and python 3.12 removed it (https://docs.python.org/3.12/whatsnew/3.12.html#importlib). The new command is find_spec and only required a few adaptions --- capnp/lib/capnp.pyx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/capnp/lib/capnp.pyx b/capnp/lib/capnp.pyx index 6e26796..dbb92b7 100644 --- a/capnp/lib/capnp.pyx +++ b/capnp/lib/capnp.pyx @@ -42,6 +42,7 @@ from types import ModuleType as _ModuleType from operator import attrgetter as _attrgetter from functools import partial as _partial from contextlib import asynccontextmanager as _asynccontextmanager +from importlib.machinery import ModuleSpec _CAPNP_VERSION_MAJOR = capnp.CAPNP_VERSION_MAJOR _CAPNP_VERSION_MINOR = capnp.CAPNP_VERSION_MINOR @@ -4322,7 +4323,7 @@ class _Importer: self.extension = '.capnp' self.additional_paths = additional_paths - def find_module(self, fullname, package_path=None): + def find_spec(self, fullname, package_path, target=None): if fullname in _sys.modules: # Don't allow re-imports return None @@ -4363,12 +4364,12 @@ class _Importer: path = abspath(path) if is_file(path+sep+capnp_module_name): - return _Loader(fullname, join_path(path, capnp_module_name), self.additional_paths) + return ModuleSpec(fullname, _Loader(fullname, join_path(path, capnp_module_name), self.additional_paths)) if has_underscores: if is_file(path+sep+capnp_module_name_dashes): - return _Loader(fullname, join_path(path, capnp_module_name_dashes), self.additional_paths) + return ModuleSpec(fullname, _Loader(fullname, join_path(path, capnp_module_name_dashes), self.additional_paths)) if is_file(path+sep+capnp_module_name_spaces): - return _Loader(fullname, join_path(path, capnp_module_name_spaces), self.additional_paths) + return ModuleSpec(fullname, _Loader(fullname, join_path(path, capnp_module_name_spaces), self.additional_paths)) _importer = None