fix(lcb): expose sys.stdin.buffer so binary-stdin solutions are graded correctly#1256
Open
avalyset wants to merge 1 commit into
Open
fix(lcb): expose sys.stdin.buffer so binary-stdin solutions are graded correctly#1256avalyset wants to merge 1 commit into
avalyset wants to merge 1 commit into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
LiveCodeBench grades solutions by running them with
sys.stdinpatched to feed the test input. That patch was aStringIO, which has no.buffer— so any correct solution reading binary stdin viasys.stdin.buffer.read(), a common competitive fast-I/O idiom, raisedAttributeErrorinsidecall_methodand was scored as failing.Fix
Replace the
StringIO+ per-methodsys.stdin.read*patches with a small stand-in,_StdinWithBuffer, that keeps the existing text behaviour byte-for-byte (read/readline/readlines) and adds a.bufferbacked by aBytesIO. AStringIOcan'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.pyadds two cases: a solution readingsys.stdin.buffer(fails onmain, passes here) and one reading text stdin (unchanged). Both green;ruffclean.Fixes #1255