Coverage for src/metaclass_registry/descendants.py: 100%

12 statements  

« prev     ^ index     » next       coverage.py v7.17.3, created at 2026-11-17 00:39 +0000

1"""A class family's members, read from the class graph instead of a hand-kept registry.""" 

2 

3from __future__ import annotations 

4 

5 

6class Descendants: 

7 """A class lists itself and every class below it, each once, depth first in the order 

8 the subclasses were declared.""" 

9 

10 @classmethod 

11 def descendants(cls) -> tuple[type, ...]: 

12 pending: list[type] = [cls] 

13 found: dict[type, None] = {} 

14 while pending: 

15 owner = pending.pop() 

16 if owner not in found: 

17 found[owner] = None 

18 pending.extend(reversed(owner.__subclasses__())) 

19 return tuple(found)