From 5093698254ba84f9d1adbe70fd8e8ddc65f65737 Mon Sep 17 00:00:00 2001 From: ishtar Date: Thu, 15 Oct 2026 00:45:34 +0900 Subject: [PATCH] Give LiveCodeBench stdin tests a stdin with a buffer run_test_std replaced sys.stdin with a StringIO, which has no .buffer attribute. A solution that reads its input through sys.stdin.buffer, the common fast-input idiom (data = sys.stdin.buffer.read().split()), raised AttributeError before printing anything, so every stdin test failed even when the solution was correct. Use a text stream over a bytes buffer instead. input(), sys.stdin.read, sys.stdin.readline and line iteration behave as before (newline="\n" keeps StringIO's newline handling), and sys.stdin.buffer now reads the test input. LiveCodeBench's own harness also gives stdin a buffer (MockStdinWithBuffer in lcb_runner/evaluation/testing_util.py). --- llm_evaluation/livecodebench_util.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/llm_evaluation/livecodebench_util.py b/llm_evaluation/livecodebench_util.py index 304db062..ed861bcf 100644 --- a/llm_evaluation/livecodebench_util.py +++ b/llm_evaluation/livecodebench_util.py @@ -303,7 +303,10 @@ def run_test_func(completion, is_extracted, test_input, test_output): def run_test_std(completion, test_input, test_output): - sys.stdin = StringIO(test_input) + # A StringIO has no .buffer, so solutions reading sys.stdin.buffer would fail. + sys.stdin = io.TextIOWrapper( + io.BytesIO(test_input.encode("utf-8")), encoding="utf-8", newline="\n" + ) output = StringIO() sys.stdout = output