@@ -31,6 +31,8 @@ class PythonCollector(BaseCollector):
31
31
**`docstring_options`** | `dict[str, Any]` | The options for the docstring parser. | `{}`
32
32
"""
33
33
34
+ fallback_config : dict = {"fallback" : True }
35
+
34
36
def __init__ (self ) -> None :
35
37
"""Initialize the object."""
36
38
self ._modules_collection : ModulesCollection = ModulesCollection ()
@@ -49,15 +51,17 @@ def collect(self, identifier: str, config: dict) -> CollectorItem: # noqa: WPS2
49
51
Returns:
50
52
The collected object-tree.
51
53
"""
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
+
52
59
final_config = ChainMap (config , self .default_config )
53
60
parser_name = final_config ["docstring_style" ]
54
61
parser_options = final_config ["docstring_options" ]
55
62
parser = parser_name and Parser (parser_name )
56
63
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 :
61
65
loader = GriffeLoader (
62
66
extensions = load_extensions (final_config .get ("extensions" , [])),
63
67
docstring_parser = parser ,
@@ -79,7 +83,7 @@ def collect(self, identifier: str, config: dict) -> CollectorItem: # noqa: WPS2
79
83
except KeyError as error : # noqa: WPS440
80
84
raise CollectionError (f"{ identifier } could not be found" ) from error
81
85
82
- if not just_loaded and doc_object .docstring is not None :
86
+ if not unknown_module and doc_object .docstring is not None :
83
87
doc_object .docstring .parser = parser
84
88
doc_object .docstring .parser_options = parser_options
85
89
0 commit comments