Skip to content

Commit 263977a

Browse files
authored
PYTHON-4424 Add workaround for ModuleNotFoundError TypeError (#1628)
1 parent 7e5945e commit 263977a

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

pymongo/_lazy_import.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,17 @@ def lazy_import(name: str) -> ModuleType:
2323
2424
From https://docs.python.org/3/library/importlib.html#implementing-lazy-imports
2525
"""
26+
# Workaround for PYTHON-4424.
27+
if "__compiled__" in globals():
28+
return importlib.import_module(name)
2629
try:
2730
spec = importlib.util.find_spec(name)
2831
except ValueError:
29-
raise ModuleNotFoundError(name=name) from None
32+
# Note: this cannot be ModuleNotFoundError, see PYTHON-4424.
33+
raise ImportError(name=name) from None
3034
if spec is None:
31-
raise ModuleNotFoundError(name=name)
35+
# Note: this cannot be ModuleNotFoundError, see PYTHON-4424.
36+
raise ImportError(name=name)
3237
assert spec is not None
3338
loader = importlib.util.LazyLoader(spec.loader) # type:ignore[arg-type]
3439
spec.loader = loader

0 commit comments

Comments
 (0)