Skip to content

Commit

Permalink
Replace deprecated find_module with find_spec (importlib)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
tobiasah committed Oct 9, 2023
1 parent 4db5d43 commit 9d7841e
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions capnp/lib/capnp.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 9d7841e

Please sign in to comment.