From 46c56c7ff505531f5422f526ad38095ed463cc1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Mazzucotelli?= Date: Mon, 4 Mar 2024 19:09:49 +0100 Subject: [PATCH] refactor: Catch index errors when finding top module in case of search path misconfiguration Issue-#246: https://github.com/mkdocstrings/griffe/issues/246 --- src/griffe/finder.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/griffe/finder.py b/src/griffe/finder.py index 01753349..caff71a5 100644 --- a/src/griffe/finder.py +++ b/src/griffe/finder.py @@ -395,10 +395,9 @@ def _top_module_name(self, path: Path) -> str: # Always resolve parent path to compare for relativeness against resolved search paths. parent_path = parent_path.resolve() for search_path in self.search_paths: - with suppress(ValueError): + with suppress(ValueError, IndexError): rel_path = parent_path.relative_to(search_path.resolve()) - top_path = search_path / rel_path.parts[0] - return top_path.name + return rel_path.parts[0] # If not, get the highest directory with an `__init__` module, # add its parent to search paths and return it. while parent_path.parent != parent_path and (parent_path.parent / "__init__.py").exists():