From 7f19432360da79d8da6810c2993e180910edbdeb Mon Sep 17 00:00:00 2001 From: Jan Lindemann Date: Wed, 15 Jul 2026 17:46:27 +0200 Subject: [PATCH] lib.Types: Exception log beautification Be a bit more verbose if a broken (i.e. non-class-type) type filter parameter gets passed. Signed-off-by: Jan Lindemann --- src/python/jw/pkg/lib/Types.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/python/jw/pkg/lib/Types.py b/src/python/jw/pkg/lib/Types.py index f38013c2..b223168a 100644 --- a/src/python/jw/pkg/lib/Types.py +++ b/src/python/jw/pkg/lib/Types.py @@ -7,7 +7,7 @@ import sys from typing import TYPE_CHECKING, Generic, Iterable, TypeVar -from .log import OFF, log, parse_log_level +from .log import ERR, OFF, log, parse_log_level if TYPE_CHECKING: from collections.abc import Iterator @@ -43,7 +43,7 @@ class LoadTypes(Types[T]): # export def __init__( self, - mod_names: list[str], + mod_names: Iterable[str], type_name_filter: str | None = None, type_filter: Sequence[type[Any]] | None = None, debug_level = None, @@ -99,8 +99,15 @@ class LoadTypes(Types[T]): # export continue if self.__type_filter: for tp in self.__type_filter: - if issubclass(c, tp): - break + try: + if issubclass(c, tp): + break + except Exception as e: + log( + ERR, + f'Failed to check if {c} inherits from {tp} ({e})' + ) + raise self._debug(f'o "{name}" is not of type {tp}') else: self._debug(f'o "{name}" doesn\'t match type filter')