Skip to content

Commit

Permalink
Do not use importlib find_module API
Browse files Browse the repository at this point in the history
This API was removed in Python 3.12
(python/cpython#98040).

Fixes Python 3.12 support in grpcio tests.
  • Loading branch information
musicinmybrain committed Jul 17, 2023
1 parent ff4c64e commit 095ddf0
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/python/grpcio_tests/tests/_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,13 @@ def _walk_package(self, package_path):
for importer, module_name, is_package in pkgutil.walk_packages(
[package_path], prefix
):
found_module = importer.find_module(module_name)
module = None
if module_name in sys.modules:
module = sys.modules[module_name]
else:
module = found_module.load_module(module_name)
spec = importer.find_spec(module_name)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
self.visit_module(module)

def visit_module(self, module):
Expand Down

0 comments on commit 095ddf0

Please sign in to comment.