Repository navigation
Description
tests/test_api_docs.py exists to keep the two entry points' docstrings honest:
evolve()grew to 25 parameters with only 9 mentioned in its docstring … This keeps the docstrings honest as the signatures change.
The check is a substring match against the whole docstring:
def _undocumented(fn):
doc = fn.__doc__ or ""
return [p for p in inspect.signature(fn).parameters if p not in doc]A parameter counts as documented if its name appears anywhere in the docstring — including in prose, in another parameter's explanation, or as a substring of a longer word.
Measured
Delete the entire Parameters section from each docstring and re-run the check:
| function | parameters | still "documented" with the Parameters section removed |
|---|---|---|
evolve |
30 | 11 |
async_evolve |
27 | 20 |
async_evolve is at 74%, because its docstring opens with a prose paragraph that lists names:
tasks,reward,agent,run,propose,strategy,initial_state,blast_radius,artifact_id,held_out_frac,repo_path,agg_config,staleness_policy,aggregator_factoryandoracle_budgetmean exactly what they do inevolve, which documents them.
That sentence alone satisfies the guard for 15 parameters, so none of them could ever be reported as undocumented no matter what happens to the docstring. It also means max_seconds, max_iters and target_reward — the three the file's own docstring calls out as "the ones that silently change cost or bound the run" — are covered by the same substring accident.
Substring matching adds more: run matches "running", "runtime", "run for you"; agent matches "agents"; parallel matches "parallelism", "data-parallel"; rounds matches "consecutive rounds", "max_wait_rounds". None of these need a parameter entry to exist.
Suggested
Check for a parameter entry, not a mention. Both docstrings use numpydoc form, so the entry is a line at a known indent ending in ::
def _undocumented(fn):
doc = inspect.getdoc(fn) or ""
body = doc.split("Parameters\n----------\n", 1)[-1]
documented = set()
for line in body.splitlines():
m = re.match(r"^(\w[\w, ]*):\s*$", line) # "max_seconds:" / "run, propose:"
if m:
documented.update(p.strip() for p in m.group(1).split(","))
return [p for p in inspect.signature(fn).parameters if p not in documented]That version fails today for whatever is genuinely undocumented, which is the information the file was written to surface.
The same file has a second soft spot
test_result_documents_the_error_contract asserts:
src = inspect.getsource(EvolutionResult)
assert "error" in src and "clean run" in src"error" in src is satisfied by the field declaration itself; "clean run" is a string that could move to any comment in the class. Neither checks that the contract — error is None on a clean run, set otherwise — is described. It is closer to a spell-check than a documentation check, in the one place where the docs make a promise the caller is told to rely on (**Check error**).
Related: #7 (the evolve/async_evolve parameter divergence this guard is meant to police).
Activity