Skip to content

Commit

Permalink
fix: Fix regression with LRU cached method
Browse files Browse the repository at this point in the history
Issue #549: #549
  • Loading branch information
pawamoy committed Apr 6, 2023
1 parent 9622e38 commit 85efbd2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/mkdocstrings/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def on_config(self, config: Config, **kwargs: Any) -> Config: # noqa: ARG002
inv_loader = futures.ThreadPoolExecutor(4)
for handler_name, import_item in to_import:
future = inv_loader.submit(
self._load_inventory,
self._load_inventory, # type: ignore[misc]
self.get_handler(handler_name).load_inventory,
**import_item,
)
Expand Down Expand Up @@ -330,9 +330,9 @@ def get_handler(self, handler_name: str) -> BaseHandler:
return self.handlers.get_handler(handler_name)

@classmethod
@functools.lru_cache(maxsize=None)
# lru_cache does not allow mutable arguments such lists, but that is what we load from YAML config.
@list_to_tuple
@functools.lru_cache(maxsize=None)
def _load_inventory(cls, loader: InventoryLoaderType, url: str, **kwargs: Any) -> Mapping[str, str]:
"""Download and process inventory files using a handler.
Expand Down
12 changes: 12 additions & 0 deletions tests/test_inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@
import sys
from io import BytesIO
from os.path import join
from typing import TYPE_CHECKING

import pytest
from mkdocs.commands.build import build
from mkdocs.config import load_config

from mkdocstrings.inventory import Inventory, InventoryItem

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


Expand Down Expand Up @@ -55,3 +58,12 @@ def test_sphinx_load_mkdocstrings_inventory_file() -> None:

for item in own_inv.values():
assert item.name in sphinx_inv[f"{item.domain}:{item.role}"]


def test_load_inventory(plugin: MkdocstringsPlugin) -> None:
"""Test the plugin inventory loading method.
Parameters:
plugin: A mkdocstrings plugin instance.
"""
plugin._load_inventory(loader=lambda *args, **kwargs: (), url="https://example.com", domains=["a", "b"]) # type: ignore[misc,arg-type]

0 comments on commit 85efbd2

Please sign in to comment.