Skip to content

fix(lcb): expose sys.stdin.buffer so binary-stdin solutions are graded correctly#1256

Open
avalyset wants to merge 1 commit into
huggingface:mainfrom
avalyset:fix/lcb-stdin-buffer
Open

fix(lcb): expose sys.stdin.buffer so binary-stdin solutions are graded correctly#1256
avalyset wants to merge 1 commit into
huggingface:mainfrom
avalyset:fix/lcb-stdin-buffer

Conversation

@avalyset

Copy link
Copy Markdown

What

LiveCodeBench grades solutions by running them with sys.stdin patched to feed the test input. That patch was a StringIO, which has no .buffer — so any correct solution reading binary stdin via sys.stdin.buffer.read(), a common competitive fast-I/O idiom, raised AttributeError inside call_method and was scored as failing.

Fix

Replace the StringIO + per-method sys.stdin.read* patches with a small stand-in, _StdinWithBuffer, that keeps the existing text behaviour byte-for-byte (read/readline/readlines) and adds a .buffer backed by a BytesIO. A StringIO can't carry a .buffer (readonly C type), so a dedicated object is the minimal way to add binary stdin without touching the text path.

Test

tests/unit/metrics/test_lcb_codegen_stdin.py adds two cases: a solution reading sys.stdin.buffer (fails on main, passes here) and one reading text stdin (unchanged). Both green; ruff clean.

Fixes #1255

The LiveCodeBench code grader patched sys.stdin with a StringIO, which has no
.buffer, so a correct solution reading binary stdin (sys.stdin.buffer) raised
AttributeError and was scored as failing. Replace the StringIO + per-method
patches with a small stdin stand-in that preserves the exact text behaviour and
additionally exposes .buffer. Add a regression test.

Fixes huggingface#1255
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Lighteval's LCB grader fails correct solutions that read sys.stdin.buffer

1 participant