Skip to content

Commit 69b8e25

Browse files
committed
fix: Don't load additional modules during fallback
1 parent fe868aa commit 69b8e25

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/mkdocstrings_handlers/python/collector.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ class PythonCollector(BaseCollector):
3131
**`docstring_options`** | `dict[str, Any]` | The options for the docstring parser. | `{}`
3232
"""
3333

34+
fallback_config: dict = {"fallback": True}
35+
3436
def __init__(self) -> None:
3537
"""Initialize the object."""
3638
self._modules_collection: ModulesCollection = ModulesCollection()
@@ -49,15 +51,17 @@ def collect(self, identifier: str, config: dict) -> CollectorItem: # noqa: WPS2
4951
Returns:
5052
The collected object-tree.
5153
"""
54+
module_name = identifier.split(".", 1)[0]
55+
unknown_module = module_name not in self._modules_collection
56+
if config.pop("fallback", False) and unknown_module:
57+
raise CollectionError("Not loading additional modules during fallback")
58+
5259
final_config = ChainMap(config, self.default_config)
5360
parser_name = final_config["docstring_style"]
5461
parser_options = final_config["docstring_options"]
5562
parser = parser_name and Parser(parser_name)
5663

57-
just_loaded = False
58-
module_name = identifier.split(".", 1)[0]
59-
if module_name not in self._modules_collection:
60-
just_loaded = True
64+
if unknown_module:
6165
loader = GriffeLoader(
6266
extensions=load_extensions(final_config.get("extensions", [])),
6367
docstring_parser=parser,
@@ -79,7 +83,7 @@ def collect(self, identifier: str, config: dict) -> CollectorItem: # noqa: WPS2
7983
except KeyError as error: # noqa: WPS440
8084
raise CollectionError(f"{identifier} could not be found") from error
8185

82-
if not just_loaded and doc_object.docstring is not None:
86+
if not unknown_module and doc_object.docstring is not None:
8387
doc_object.docstring.parser = parser
8488
doc_object.docstring.parser_options = parser_options
8589

0 commit comments

Comments
 (0)