Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AA-Turner committed Jan 19, 2025
1 parent d5f4a97 commit 17ed430
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions sphinx/ext/autodoc/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ def import_module(modname: str, try_reload: bool = False) -> Any:
if spec is None:
msg = f'No module named {modname!r}'
raise ModuleNotFoundError(msg, name=modname) # NoQA: TRY301
pyi_path = None
if spec.origin is not None:
# Try finding a spec for a '.pyi' stubs file for native modules.
for suffix in _NATIVE_SUFFIXES:
Expand All @@ -178,11 +179,14 @@ def import_module(modname: str, try_reload: bool = False) -> Any:
if pyi_spec is not None:
spec = pyi_spec
break
if spec.loader is None:
msg = 'missing loader'
raise ImportError(msg, name=spec.name) # NoQA: TRY301
sys.modules[modname] = module = module_from_spec(spec)
spec.loader.exec_module(module)
if pyi_path is None:
module = importlib.import_module(modname)
else:
if spec.loader is None:
msg = 'missing loader'
raise ImportError(msg, name=spec.name) # NoQA: TRY301
sys.modules[modname] = module = module_from_spec(spec)
spec.loader.exec_module(module)
except ImportError:
raise
except BaseException as exc:
Expand Down

0 comments on commit 17ed430

Please sign in to comment.