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 <jan@janware.com>
This commit is contained in:
Jan Lindemann 2026-07-13 20:21:29 +02:00 • committed by janware DevOps
commit 20a8ab91f7
Signed by: DevOps
SSH key fingerprint: SHA256:cZiw7ExG5q3KAVm7Jse3rGITowu0VjgUgNMPbifmY8g

View file

@ -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,