Skip to content

Commit 83823be

Browse files
authored
feat: Add force_inspection option to force dynamic analysis
Griffe supports this option but mkdocstrings-python didn't allow users to configure it. Issue-94: #94 PR-231: #231
1 parent 84ea8a4 commit 83823be

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

docs/usage/configuration/general.md

+24
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,30 @@ plugins:
5555
////
5656
///
5757
58+
## `force_inspection`
59+
60+
- **:octicons-package-24: Type [`bool`][] :material-equal: `False`{ title="default value" }**
61+
<!-- - **:octicons-project-template-24: Template :material-null:** (contained in [`class.html`][class template]) -->
62+
63+
Whether to force inspecting modules (importing them) even if their source code is available.
64+
65+
This option is useful when you know that dynamic analysis (inspection) yields better results than static analysis. Do not use this blindly: the recommended approach is to write a Griffe extension that will improve extracted API data. See [How to selectively inspect objects](https://mkdocstrings.github.io/griffe/guide/users/how-to/selectively-inspect/).
66+
67+
```yaml title="in mkdocs.yml (global configuration)"
68+
plugins:
69+
- mkdocstrings:
70+
handlers:
71+
python:
72+
options:
73+
force_inspection: false
74+
```
75+
76+
```md title="or in docs/some_page.md (local configuration)"
77+
::: path.to.object
78+
options:
79+
force_inspection: true
80+
```
81+
5882
## `show_bases`
5983

6084
- **:octicons-package-24: Type [`bool`][] :material-equal: `True`{ title="default value" }**

src/mkdocstrings_handlers/python/handler.py

+3
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ class PythonHandler(BaseHandler):
116116
"annotations_path": "brief",
117117
"preload_modules": None,
118118
"allow_inspection": True,
119+
"force_inspection": False,
119120
"summary": False,
120121
"show_labels": True,
121122
"unwrap_annotated": False,
@@ -127,6 +128,7 @@ class PythonHandler(BaseHandler):
127128
Attributes: General options:
128129
find_stubs_package (bool): Whether to load stubs package (package-stubs) when extracting docstrings. Default `False`.
129130
allow_inspection (bool): Whether to allow inspecting modules when visiting them is not possible. Default: `True`.
131+
force_inspection (bool): Whether to force using dynamic analysis when loading data. Default: `False`.
130132
show_bases (bool): Show the base classes of a class. Default: `True`.
131133
show_inheritance_diagram (bool): Show the inheritance diagram of a class using Mermaid. Default: `False`.
132134
show_source (bool): Show the source code of this object. Default: `True`.
@@ -318,6 +320,7 @@ def collect(self, identifier: str, config: Mapping[str, Any]) -> CollectorItem:
318320
modules_collection=self._modules_collection,
319321
lines_collection=self._lines_collection,
320322
allow_inspection=final_config["allow_inspection"],
323+
force_inspection=final_config["force_inspection"],
321324
)
322325
try:
323326
for pre_loaded_module in final_config.get("preload_modules") or []:

0 commit comments

Comments
 (0)