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 <jan@janware.com>
This commit is contained in:
parent
db09928ffa
commit
7f19432360
1 changed files with 11 additions and 4 deletions
|
|
@ -7,7 +7,7 @@ import sys
|
||||||
|
|
||||||
from typing import TYPE_CHECKING, Generic, Iterable, TypeVar
|
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:
|
if TYPE_CHECKING:
|
||||||
from collections.abc import Iterator
|
from collections.abc import Iterator
|
||||||
|
|
@ -43,7 +43,7 @@ class LoadTypes(Types[T]): # export
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
mod_names: list[str],
|
mod_names: Iterable[str],
|
||||||
type_name_filter: str | None = None,
|
type_name_filter: str | None = None,
|
||||||
type_filter: Sequence[type[Any]] | None = None,
|
type_filter: Sequence[type[Any]] | None = None,
|
||||||
debug_level = None,
|
debug_level = None,
|
||||||
|
|
@ -99,8 +99,15 @@ class LoadTypes(Types[T]): # export
|
||||||
continue
|
continue
|
||||||
if self.__type_filter:
|
if self.__type_filter:
|
||||||
for tp in self.__type_filter:
|
for tp in self.__type_filter:
|
||||||
if issubclass(c, tp):
|
try:
|
||||||
break
|
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}')
|
self._debug(f'o "{name}" is not of type {tp}')
|
||||||
else:
|
else:
|
||||||
self._debug(f'o "{name}" doesn\'t match type filter')
|
self._debug(f'o "{name}" doesn\'t match type filter')
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue