From a053ca58f5fddd2e70599e3a84b5791696a53752 Mon Sep 17 00:00:00 2001 From: Romain Cledat Date: Wed, 31 Jan 2024 22:49:21 -0800 Subject: [PATCH] feat: Add option to search for stubs packages This allows using the feature in griffe that searches for stubs packages Related: https://github.com/mkdocstrings/griffe/pull/221 --- src/mkdocstrings_handlers/python/handler.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/mkdocstrings_handlers/python/handler.py b/src/mkdocstrings_handlers/python/handler.py index 9f6cae4b..5f238a6d 100644 --- a/src/mkdocstrings_handlers/python/handler.py +++ b/src/mkdocstrings_handlers/python/handler.py @@ -61,6 +61,7 @@ class PythonHandler(BaseHandler): fallback_config: ClassVar[dict] = {"fallback": True} """The configuration used to collect item during autorefs fallback.""" default_config: ClassVar[dict] = { + "find_stubs_package": False, "docstring_style": "google", "docstring_options": {}, "show_symbol_type_heading": False, @@ -110,6 +111,7 @@ class PythonHandler(BaseHandler): """Default handler configuration. Attributes: General options: + find_stubs_package (bool): Whether to load stubs package (package-stubs) when extracting docstrings allow_inspection (bool): Whether to allow inspecting modules when visiting them is not possible. Default: `True`. show_bases (bool): Show the base classes of a class. Default: `True`. show_source (bool): Show the source code of this object. Default: `True`. @@ -279,7 +281,7 @@ def collect(self, identifier: str, config: Mapping[str, Any]) -> CollectorItem: try: for pre_loaded_module in final_config.get("preload_modules") or []: if pre_loaded_module not in self._modules_collection: - loader.load(pre_loaded_module) + loader.load(pre_loaded_module, find_stubs_package=final_config["find_stubs_package"]) loader.load(module_name) except ImportError as error: raise CollectionError(str(error)) from error