Answer principles round 1: 1 🔴, 7 🟡 (0 misread); every effect is handed in as an argument, no test patches a global, and the traces principle scopes tools that run on their user's machine
CI / tests (pull_request) Successful in 3m43s
CI / tests (pull_request) Successful in 3m43s
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
"""Replay archived cases on a rung, as judge-replay and review-replay both do; and judge-replay's rung search, which holds each candidate rung to what a reference rung reproduced."""
|
||||
import concurrent.futures
|
||||
import dataclasses
|
||||
import sys
|
||||
import typing
|
||||
|
||||
from failure import Failure
|
||||
@@ -49,6 +48,8 @@ def replayed(
|
||||
replay_one: typing.Callable[[Case, Rung], Answer | Limited],
|
||||
reproduced: typing.Callable[[Case, Answer], list[Aim]],
|
||||
what: str,
|
||||
say: typing.Callable[[str], None],
|
||||
at_once: int,
|
||||
climbs: typing.Sequence[Rung] = (),
|
||||
) -> Replay[Case, Aim, Answer] | Limited:
|
||||
"""Replays the cases on the reference rung, then on each climb and each candidate, on the cases where the reference reproduced anything.
|
||||
@@ -57,7 +58,7 @@ def replayed(
|
||||
|
||||
The candidates are tried highest first, until one misses an item the reference reproduced. Going down, every candidate at or above the one named was tried and didn't miss anything, so the result needs no assumption that a higher rung does at least as well; and a miss high up spares the cheaper rungs their replays.
|
||||
"""
|
||||
on_reference = replayed_on(cases, reference, replay_one, what)
|
||||
on_reference = replayed_on(cases, reference, replay_one, what, say, at_once)
|
||||
if isinstance(on_reference, Limited):
|
||||
return on_reference
|
||||
held = [(case, aim) for case, reply in zip(cases, on_reference) if (aim := reproduced(case, reply))]
|
||||
@@ -66,14 +67,14 @@ def replayed(
|
||||
return Replay(on_reference, [], None)
|
||||
climbed: list[Tried[Case, Aim, Answer]] = []
|
||||
for rung in climbs:
|
||||
climb = tried_on(held, rung, replay_one, reproduced, what)
|
||||
climb = tried_on(held, rung, replay_one, reproduced, what, say, at_once)
|
||||
if isinstance(climb, Limited):
|
||||
return climb
|
||||
climbed.append(climb)
|
||||
tried: list[Tried[Case, Aim, Answer]] = []
|
||||
lowest = None
|
||||
for rung in candidates:
|
||||
candidate = tried_on(held, rung, replay_one, reproduced, what)
|
||||
candidate = tried_on(held, rung, replay_one, reproduced, what, say, at_once)
|
||||
if isinstance(candidate, Limited):
|
||||
return candidate
|
||||
tried.append(candidate)
|
||||
@@ -89,9 +90,11 @@ def tried_on(
|
||||
replay_one: typing.Callable[[Case, Rung], Answer | Limited],
|
||||
reproduced: typing.Callable[[Case, Answer], list[Aim]],
|
||||
what: str,
|
||||
say: typing.Callable[[str], None],
|
||||
at_once: int,
|
||||
) -> Tried[Case, Aim, Answer] | Limited:
|
||||
"""rung and each item, of those the reference reproduced in the held cases, that its replies missed."""
|
||||
replies = replayed_on([case for case, _ in held], rung, replay_one, what)
|
||||
replies = replayed_on([case for case, _ in held], rung, replay_one, what, say, at_once)
|
||||
if isinstance(replies, Limited):
|
||||
return replies
|
||||
misses: list[Miss[Case, Aim, Answer]] = []
|
||||
@@ -101,10 +104,10 @@ def tried_on(
|
||||
return Tried(rung, misses)
|
||||
|
||||
|
||||
def replayed_on(cases: list[Case], rung: Rung, replay_one: typing.Callable[[Case, Rung], Answer | Limited], what: str) -> list[Answer] | Limited:
|
||||
"""Each case's reply on rung, AT_ONCE at a time; a usage limit cancels the rest."""
|
||||
print(f"replaying {len(cases)} {what} on {rung}", file=sys.stderr, flush=True)
|
||||
with concurrent.futures.ThreadPoolExecutor(AT_ONCE) as pool:
|
||||
def replayed_on(cases: list[Case], rung: Rung, replay_one: typing.Callable[[Case, Rung], Answer | Limited], what: str, say: typing.Callable[[str], None], at_once: int) -> list[Answer] | Limited:
|
||||
"""Each case's reply on rung, at_once at a time, after telling say what it replays; a usage limit cancels the rest."""
|
||||
say(f"replaying {len(cases)} {what} on {rung}")
|
||||
with concurrent.futures.ThreadPoolExecutor(at_once) as pool:
|
||||
running = [pool.submit(replay_one, case, rung) for case in cases]
|
||||
replies: list[Answer] = []
|
||||
for future in running:
|
||||
|
||||
Reference in New Issue
Block a user