Skip to content

Commit 5934b2b

Browse files
committed
Merge branch 'master' of github.com:mongodb/mongo-python-driver
2 parents 089d4a5 + 263977a commit 5934b2b

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

pymongo/_lazy_import.py

Lines changed: 7 additions & 2 deletions
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)