karenina.benchmark.verification.utils.class_discovery¶
class_discovery
¶
Utility for discovering BaseAnswer subclasses in exec() namespaces.
Replaces the hardcoded local_ns["Answer"] lookup with a scan that finds any BaseAnswer subclass, supporting custom class names.
Classes¶
Functions¶
find_answer_class
¶
find_answer_class(local_ns: dict[str, object]) -> type
Find the leaf BaseAnswer subclass in a namespace.
Scans for classes that inherit from BaseAnswer, excluding BaseAnswer itself and intermediate base classes that have further subclasses in the same namespace.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
dict[str, object]
|
The namespace dict (typically from exec()). |
required |
Returns:
| Type | Description |
|---|---|
type
|
The single leaf BaseAnswer subclass found. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If zero or multiple leaf subclasses are found. |