Skip to content

feat: allow force_inspection option to be configurable #231

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions docs/usage/configuration/general.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,30 @@ plugins:
////
///

## `force_inspection`

- **:octicons-package-24: Type [`bool`][] :material-equal: `False`{ title="default value" }**
<!-- - **:octicons-project-template-24: Template :material-null:** (contained in [`class.html`][class template]) -->

Whether to force inspecting modules (importing them) even if their source code is available.

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/).

```yaml title="in mkdocs.yml (global configuration)"
plugins:
- mkdocstrings:
handlers:
python:
options:
force_inspection: false
```

```md title="or in docs/some_page.md (local configuration)"
::: path.to.object
options:
force_inspection: true
```

## `show_bases`

- **:octicons-package-24: Type [`bool`][] :material-equal: `True`{ title="default value" }**
Expand Down
3 changes: 3 additions & 0 deletions src/mkdocstrings_handlers/python/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ class PythonHandler(BaseHandler):
"annotations_path": "brief",
"preload_modules": None,
"allow_inspection": True,
"force_inspection": False,
"summary": False,
"show_labels": True,
"unwrap_annotated": False,
Expand All @@ -127,6 +128,7 @@ class PythonHandler(BaseHandler):
Attributes: General options:
find_stubs_package (bool): Whether to load stubs package (package-stubs) when extracting docstrings. Default `False`.
allow_inspection (bool): Whether to allow inspecting modules when visiting them is not possible. Default: `True`.
force_inspection (bool): Whether to force using dynamic analysis when loading data. Default: `False`.
show_bases (bool): Show the base classes of a class. Default: `True`.
show_inheritance_diagram (bool): Show the inheritance diagram of a class using Mermaid. Default: `False`.
show_source (bool): Show the source code of this object. Default: `True`.
Expand Down Expand Up @@ -318,6 +320,7 @@ def collect(self, identifier: str, config: Mapping[str, Any]) -> CollectorItem:
modules_collection=self._modules_collection,
lines_collection=self._lines_collection,
allow_inspection=final_config["allow_inspection"],
force_inspection=final_config["force_inspection"],
)
try:
for pre_loaded_module in final_config.get("preload_modules") or []:
Expand Down
Loading