misc.load_class(): Beautify exception message
Depending on whether or not a name or type filter is used, the exception message of load_class() can be a bit confusing. Fix that. Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
d4fd741c19
commit
3dd5255c90
1 changed files with 10 additions and 11 deletions
|
|
@ -101,17 +101,16 @@ def load_class(module_path, baseclass, class_name_filter = None): # export
|
|||
classes = LoadTypes(
|
||||
[module_path], type_name_filter = class_name_filter, type_filter = type_filter
|
||||
).classes
|
||||
if len(classes) == 0:
|
||||
raise Exception(
|
||||
f'no class matching "{class_name_filter}" of type "{baseclass}" '
|
||||
f'found in module "{module_path}"'
|
||||
)
|
||||
if len(classes) > 1:
|
||||
raise Exception(
|
||||
f'{len(classes)} classes matching "{class_name_filter}" of type '
|
||||
f'"{baseclass}" found in module "{module_path}"'
|
||||
)
|
||||
return classes[0]
|
||||
size = len(list(classes))
|
||||
if size != 1:
|
||||
msg = f'{size} classes'
|
||||
if class_name_filter is not None:
|
||||
msg += f' matching "{class_name_filter}'
|
||||
if baseclass is not None:
|
||||
msg += f' of type "{baseclass}" '
|
||||
msg += f'found in module "{module_path}"'
|
||||
raise Exception(msg)
|
||||
return next(iter(classes))
|
||||
|
||||
def load_class_names(path, baseclass, flt = None, remove_flt = False): # export
|
||||
classes = load_classes(path, baseclass, flt)
|
||||
|
|
|
|||
Loading…
Reference in a new issue