Coverage for src/metaclass_registry/abstract_hooks.py: 100%
6 statements
« prev ^ index » next coverage.py v7.17.3, created at 2026-11-17 00:39 +0000
« prev ^ index » next coverage.py v7.17.3, created at 2026-11-17 00:39 +0000
1"""Abstract methods enforced without ABCMeta."""
3from __future__ import annotations
5from typing import Any
8class AbstractHooksMeta(type):
9 """A class whose MRO declares an abstract method it still resolves can't be built.
11 ABCMeta does the same but replaces isinstance and issubclass, which doubles their
12 cost on every check. This reads the whole MRO once, at class creation, so a plain
13 mixin's abstract hooks count as well as a declared base's. Assigning
14 __abstractmethods__ sets the flag object.__new__ refuses on.
15 """
17 def __init__(
18 cls, name: str, bases: tuple[type, ...], namespace: dict[str, Any], **kwargs: Any
19 ) -> None:
20 super().__init__(name, bases, namespace, **kwargs)
21 cls.__abstractmethods__ = frozenset(
22 member
23 for base in cls.__mro__
24 for member, value in vars(base).items()
25 if getattr(value, "__isabstractmethod__", False)
26 and getattr(getattr(cls, member, None), "__isabstractmethod__", False)
27 )