Skip to content

Commit

Permalink
update based on experimentation
Browse files Browse the repository at this point in the history
  • Loading branch information
blink1073 committed May 2, 2024
1 parent 4c5f06c commit ff950f0
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions pymongo/_lazy_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,17 @@ def lazy_import(name: str) -> ModuleType:
From https://docs.python.org/3/library/importlib.html#implementing-lazy-imports
"""
# Workaround for PYTHON-4424.
if "__compiled__" in globals():
return importlib.import_module(name)
try:
spec = importlib.util.find_spec(name)
except ValueError:
try:
raise ModuleNotFoundError(name=name) from None
except TypeError: # Workaround for PYTHON-4424
raise ModuleNotFoundError() from None
# Note: this cannot be ModuleNotFoundError, see PYTHON-4424.
raise ImportError(name=name) from None
if spec is None:
try:
raise ModuleNotFoundError(name=name)
except TypeError: # Workaround for PYTHON-4424
raise ModuleNotFoundError() from None
# Note: this cannot be ModuleNotFoundError, see PYTHON-4424.
raise ImportError(name=name)
assert spec is not None
loader = importlib.util.LazyLoader(spec.loader) # type:ignore[arg-type]
spec.loader = loader
Expand Down

0 comments on commit ff950f0

Please sign in to comment.