lib.Types: Restrict LoadTypes to ABC-derived classes #90
1 changed files with 8 additions and 5 deletions
|
|
@ -5,7 +5,7 @@ import os
|
|||
import re
|
||||
import sys
|
||||
|
||||
from typing import TYPE_CHECKING, Any, Generic, Iterable, TypeVar, override
|
||||
from typing import TYPE_CHECKING, Any, Generic, Iterable, TypeGuard, TypeVar, override
|
||||
|
||||
from .log import ERR, OFF, log, parse_log_level
|
||||
|
||||
|
|
@ -15,6 +15,9 @@ if TYPE_CHECKING:
|
|||
|
||||
T = TypeVar('T')
|
||||
|
||||
def is_abc_class(c: type[object]) -> TypeGuard[abc.ABCMeta]:
|
||||
return isinstance(c, abc.ABCMeta)
|
||||
|
||||
class Types(abc.ABC, Iterable[type[T]], Generic[T]): # export
|
||||
|
||||
@override
|
||||
|
|
@ -101,11 +104,11 @@ class LoadTypes(Types[T]): # export
|
|||
if rx is not None and not re.match(rx, member_name):
|
||||
self._debug(f'o "{name}" has wrong name')
|
||||
continue
|
||||
if not is_abc_class(c):
|
||||
self._debug(f'o "{name}" is not derived from ABCMeta')
|
||||
continue
|
||||
if inspect.isabstract(c):
|
||||
abstract: frozenset[str] = getattr(
|
||||
c, '__abstractmethods__', frozenset()
|
||||
)
|
||||
self._debug(f'o "{name}" is abstract: {abstract}')
|
||||
self._debug(f'o "{name}" is abstract: {c.__abstractmethods__}')
|
||||
continue
|
||||
if self.__type_filter:
|
||||
for tp in self.__type_filter:
|
||||
|
|
|
|||
Loading…
Reference in a new issue