[Bugfix][Docs] Fix ReadTheDocs build crash from mocked torch decorator (#39284)
Signed-off-by: khluu <khluu000@gmail.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
78434b923c
commit
6155bbd1dd
@@ -59,7 +59,7 @@ class PydanticMagicMock(MagicMock):
|
|||||||
"""`MagicMock` that's able to generate pydantic-core schemas."""
|
"""`MagicMock` that's able to generate pydantic-core schemas."""
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
name = kwargs.pop("name", None)
|
name = kwargs.get("name")
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
self.__spec__ = ModuleSpec(name, None)
|
self.__spec__ = ModuleSpec(name, None)
|
||||||
|
|
||||||
@@ -85,7 +85,8 @@ def auto_mock(module_name: str, attr: str, max_mocks: int = 100):
|
|||||||
logger.info("Mocking %s for argparse doc generation", e.name)
|
logger.info("Mocking %s for argparse doc generation", e.name)
|
||||||
sys.modules[e.name] = PydanticMagicMock(name=e.name)
|
sys.modules[e.name] = PydanticMagicMock(name=e.name)
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.exception("Failed to import %s.%s: %s", module_name, attr)
|
logger.exception("Failed to import %s.%s", module_name, attr)
|
||||||
|
raise
|
||||||
|
|
||||||
raise ImportError(
|
raise ImportError(
|
||||||
f"Failed to import {module_name}.{attr} after mocking {max_mocks} imports"
|
f"Failed to import {module_name}.{attr} after mocking {max_mocks} imports"
|
||||||
|
|||||||
Reference in New Issue
Block a user