Skip to content

Commit 85efbd2

Browse files
committed
fix: Fix regression with LRU cached method
Issue #549: #549
1 parent 9622e38 commit 85efbd2

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

src/mkdocstrings/plugin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ def on_config(self, config: Config, **kwargs: Any) -> Config: # noqa: ARG002
231231
inv_loader = futures.ThreadPoolExecutor(4)
232232
for handler_name, import_item in to_import:
233233
future = inv_loader.submit(
234-
self._load_inventory,
234+
self._load_inventory, # type: ignore[misc]
235235
self.get_handler(handler_name).load_inventory,
236236
**import_item,
237237
)
@@ -330,9 +330,9 @@ def get_handler(self, handler_name: str) -> BaseHandler:
330330
return self.handlers.get_handler(handler_name)
331331

332332
@classmethod
333-
@functools.lru_cache(maxsize=None)
334333
# lru_cache does not allow mutable arguments such lists, but that is what we load from YAML config.
335334
@list_to_tuple
335+
@functools.lru_cache(maxsize=None)
336336
def _load_inventory(cls, loader: InventoryLoaderType, url: str, **kwargs: Any) -> Mapping[str, str]:
337337
"""Download and process inventory files using a handler.
338338

tests/test_inventory.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@
55
import sys
66
from io import BytesIO
77
from os.path import join
8+
from typing import TYPE_CHECKING
89

910
import pytest
1011
from mkdocs.commands.build import build
1112
from mkdocs.config import load_config
1213

1314
from mkdocstrings.inventory import Inventory, InventoryItem
1415

16+
if TYPE_CHECKING:
17+
from mkdocstrings.plugin import MkdocstringsPlugin
1518
sphinx = pytest.importorskip("sphinx.util.inventory", reason="Sphinx is not installed")
1619

1720

@@ -55,3 +58,12 @@ def test_sphinx_load_mkdocstrings_inventory_file() -> None:
5558

5659
for item in own_inv.values():
5760
assert item.name in sphinx_inv[f"{item.domain}:{item.role}"]
61+
62+
63+
def test_load_inventory(plugin: MkdocstringsPlugin) -> None:
64+
"""Test the plugin inventory loading method.
65+
66+
Parameters:
67+
plugin: A mkdocstrings plugin instance.
68+
"""
69+
plugin._load_inventory(loader=lambda *args, **kwargs: (), url="https://example.com", domains=["a", "b"]) # type: ignore[misc,arg-type]

0 commit comments

Comments
 (0)