From 20a8ab91f79f25efc495239d35be5db46e4f0686 Mon Sep 17 00:00:00 2001 From: Jan Lindemann Date: Mon, 13 Jul 2026 20:21:29 +0200 Subject: [PATCH] misc.load_object(): Allow multi-value module path load_path() takes a string as module path. To broaded its versatility, allow also multiple strings to be searched in order. Signed-off-by: Jan Lindemann --- src/python/jw/util/misc.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/python/jw/util/misc.py b/src/python/jw/util/misc.py index 7c4959a..0485613 100644 --- a/src/python/jw/util/misc.py +++ b/src/python/jw/util/misc.py @@ -96,13 +96,15 @@ def load_classes( # export return ret def load_class( # export - module_path: str, + module_path: str | Iterable[str], baseclass: type, class_name_filter: str | None = None ) -> type[Any]: + if isinstance(module_path, str): + module_path = [module_path] type_filter = None if baseclass is None else [baseclass] classes: Iterable[type[Any]] = LoadTypes( - [module_path], type_name_filter = class_name_filter, type_filter = type_filter + module_path, type_name_filter = class_name_filter, type_filter = type_filter ).classes size = len(list(classes)) if size != 1: @@ -111,7 +113,7 @@ def load_class( # export msg += f' matching "{class_name_filter}' if baseclass is not None: msg += f' of type "{baseclass}" ' - msg += f'found in module "{module_path}"' + msg += f'found in modules {", ".join(module_path)}' for c in classes: log.slog(log.ERR, f'Found {c!r}') raise Exception(msg) @@ -136,7 +138,7 @@ def load_class_names( # export return ret def load_object( # export - module_path: str, + module_path: str | Iterable[str], baseclass: type, class_name_filter: str|None = None, *args,