lib.Types: Read __abstractmethods__ via getattr() #89

Merged
Jan Lindemann merged 1 commit from jan/feature/20260907-lib-types-read-abstractmethods-via-getattr into master 2026-09-07 07:17:01 +02:00 AGit
Showing only changes of commit ff6e13e09f - Show all commits

lib.Types: Read __abstractmethods__ via getattr()
All checks were successful
CI / Packaging - Kali Linux (pull_request) Successful in 4m19s
CI / Packaging - OpenSUSE Tumbleweed (pull_request) Successful in 4m19s
CI / Packaging test (pull_request) Successful in 0s
CI / Packaging - Kali Linux (push) Successful in 4m8s
CI / Packaging - OpenSUSE Tumbleweed (push) Successful in 4m6s
CI / Packaging test (push) Successful in 0s

LoadTypes._classes() reads the __abstractmethods__ attribute of each class
that inspect.getmembers() returns for its debug output. mypy 2.2.0 allows
this, mypy 2.3.1 doesn't: It now types those classes as type[object]
instead of Any. The attribute itself is only declared on the ABCMeta
metaclass, so the direct access fails the type check.

Read the attribute through getattr() with an 'unknown' fallback string, and
annotate the variable explicitly. The runtime behavior is unchanged, since
the attribute exists whenever inspect.isabstract() is true, and the call
satisfies the checker.

Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v0.84.2
Signed-off-by: user.email <jan@janware.com>
Jan Lindemann 2026-09-07 06:43:56 +02:00 committed by user.email
Signed by: Jan Lindemann
GPG key ID: 3750640C9E25DD61

View file

@ -102,7 +102,10 @@ class LoadTypes(Types[T]): # export
self._debug(f'o "{name}" has wrong name') self._debug(f'o "{name}" has wrong name')
continue continue
if inspect.isabstract(c): if inspect.isabstract(c):
self._debug(f'o "{name}" is abstract: {c.__abstractmethods__}') abstract: frozenset[str] = getattr(
c, '__abstractmethods__', frozenset()
)
self._debug(f'o "{name}" is abstract: {abstract}')
continue continue
if self.__type_filter: if self.__type_filter:
for tp in self.__type_filter: for tp in self.__type_filter: