Skip to content

Commit

Permalink
refactor: Make _load_inventory accept lists as arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea authored Jan 19, 2023
1 parent 4a8a26c commit 105ed82
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/mkdocstrings/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@
InventoryLoaderType = Callable[..., Iterable[Tuple[str, str]]]


def list_to_tuple(function: Callable[..., Any]) -> Callable[..., Any]:
"""Decorater to convert lists to tuples in the arguments."""

def wrapper(*args: Any, **kwargs: Any):
safe_args = [tuple(item) if isinstance(item, list) else item for item in args]
if kwargs:
kwargs = {key: tuple(value) if isinstance(value, list) else value for key, value in kwargs.items()}
return function(*safe_args, **kwargs)

return wrapper


class MkdocstringsPlugin(BasePlugin):
"""An `mkdocs` plugin.
Expand Down Expand Up @@ -300,6 +312,8 @@ def get_handler(self, handler_name: str) -> BaseHandler:
return self.handlers.get_handler(handler_name)

@classmethod
# 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

0 comments on commit 105ed82

Please sign in to comment.