8000 fix: Make `load_external_modules` a global-only option · Viicos/python@266f41f · GitHub
[go: up one dir, main page]

Skip to content

Commit 266f41f

Browse files
committed
fix: Make load_external_modules a global-only option
Issue mkdocstrings#87: mkdocstrings#87
1 parent ee021be commit 266f41f

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/mkdocstrings_handlers/python/handler.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ class PythonHandler(BaseHandler):
108108
"filters": ["!^_[^_]"],
109109
"annotations_path": "brief",
110110
"preload_modules": None,
111-
"load_external_modules": False,
112111
"allow_inspection": True,
113112
}
114113
"""
@@ -189,6 +188,7 @@ def __init__(
189188
config_file_path: str | None = None,
190189
paths: list[str] | None = None,
191190
locale: str = "en",
191+
load_external_modules: bool = False,
192192
**kwargs: Any,
193193
) -> None:
194194
"""Initialize the handler.
@@ -198,10 +198,12 @@ def __init__(
198198
config_file_path: The MkDocs configuration file path.
199199
paths: A list of paths to use as Griffe search paths.
200200
locale: The locale to use when rendering content.
201+
load_external_modules: Load external modules when resolving aliases.
201202
**kwargs: Same thing, but with keyword arguments.
202203
"""
203204
super().__init__(*args, **kwargs)
204205
self._config_file_path = config_file_path
206+
self._load_external_modules = load_external_modules
205207
paths = paths or []
206208
glob_base_dir = os.path.dirname(os.path.abspath(config_file_path)) if config_file_path else "."
207209
with chdir(glob_base_dir):
@@ -282,7 +284,7 @@ def collect(self, identifier: str, config: Mapping[str, Any]) -> CollectorItem:
282284
raise CollectionError(str(error)) from error
283285
unresolved, iterations = loader.resolve_aliases(
284286
implicit=False,
285-
external=final_config["load_external_modules"],
287+
external=self._load_external_modules,
286288
)
287289
if unresolved:
288290
logger.debug(f"{len(unresolved)} aliases were still unresolved after {iterations} iterations")
@@ -372,11 +374,13 @@ def get_anchors(self, data: CollectorItem) -> tuple[str, ...]: # noqa: D102 (ig
372374

373375

374376
def get_handler(
377+
*,
375378
theme: str,
376379
custom_templates: str | None = None,
377380
config_file_path: str | None = None,
378381
paths: list[str] | None = None,
379382
locale: str = "en",
383+
load_external_modules: bool = False,
380384
**config: Any, # noqa: ARG001
381385
) -> PythonHandler:
382386
"""Simply return an instance of `PythonHandler`.
@@ -387,6 +391,7 @@ def get_handler(
387391
config_file_path: The MkDocs configuration file path.
388392
paths: A list of paths to use as Griffe search paths.
389393
locale: The locale to use when rendering content.
394+
load_external_modules: Load external modules when resolving aliases.
390395
**config: Configuration passed to the handler.
391396
392397
Returns:
@@ -399,4 +404,5 @@ def get_handler(
399404
config_file_path=config_file_path,
400405
paths=paths,
401406
locale=locale,
407+
load_external_modules=load_external_modules,
402408
)

0 commit comments

Comments
 (0)
0