"""Revision point 3: verify_article.py reads every row-format protocol sweep through ONE loader, which serves the re-scoring under the single (bracketing) criterion from sweep_uniform.json. Exact anchors, each replaced the stated number of times, or nothing is written. python -u apply_verify_uniform.py """ from __future__ import annotations import re PATH = "verify_article.py" src = open(PATH, encoding="utf8").read() # 1. every `with open(, encoding="utf8") as fh:\n name = json.load(fh)` -> name = _load() pat = re.compile(r'( *)with open\(([^,]+), encoding="utf8"\) as fh:\n +(\w+) = json\.load\(fh\)\n') n_sub = len(pat.findall(src)) assert n_sub == 9, n_sub src = pat.sub(lambda m: f"{m.group(1)}{m.group(3)} = _load({m.group(2)})\n", src) # 2. the loader itself: row-format protocol sweeps come from the single-criterion re-scoring old_loader = '''def _load(path): with open(path, encoding="utf8") as fh: return json.load(fh) ''' new_loader = '''def _load(path): """A results file. A row-format protocol sweep (a list of labelled cells) is served from sweep_uniform.json, its re-scoring under the paper's single criterion - a sign change within 1e-6 or f(x) == 0 (revision point 3, 2026-09-22); every other file as stored.""" from rescore_uniform import load_uniform with open(path, encoding="utf8") as fh: data = json.load(fh) if isinstance(data, list) and data and "spec" in data[0]: return load_uniform(path) return data ''' assert src.count(old_loader) == 1 src = src.replace(old_loader, new_loader) open(PATH, "w", encoding="utf8").write(src) print(f"replaced {n_sub} direct reads and the loader")