Repository navigation
Conversation
Contributor
Author
|
|
jserv
requested changes
Nov 22, 2026
jserv
left a comment
Contributor
There was a problem hiding this comment.
Rebase the current branch onto the upstream default branch and resolve any conflicts. Run /codetrial-review in AI agents (use $codetrial-review in Codex) and resolve all identified issues. Rework the series into minimal, logically coherent commits, squash closely related commits, and ensure all commit messages follow the project’s rules.
jserv
reviewed
Nov 22, 2026
jserv
reviewed
Nov 22, 2026
The Python driver built one Solution for the whole run, while the C++ and Java harnesses build one inside each case, so an answer that keeps state on self started each case with what the earlier cases left: on Grid Segment Net Yield the usual Binary Tree Maximum Path Sum answer passed 2 of 6, every later case returning 42, though it passes all 6 in C++. Solution() also ran inside the try that reports a missing method, so an __init__ that raised read as "Could not find bestRouteYield in your code". Build it inside each case's try instead, after the setup check that the class defines the entry, so the work __init__ does now counts toward each case's timeMs and the run's 5 s budget. The driver is exported so a new test runs it on CPython from node --test, as asked on sysprog21#783: besides the reported answer, it checks that every case runs on an object __init__ built for it alone and that a constructor error fails only its own case, and it skips only when the interpreter is missing. Close sysprog21#799 Change-Id: I2f53fef2bae477241d763a5249f772980b6d2856
The previous commit reworked the branch of the Python driver that builds the Solution an answer's entry is called on. Pin on CPython what it keeps around that branch: a Solution without the entry method is still a setup error, a class judge's methods within one case share an instance while the next case starts a new one, and an answer written as a plain module-level function still runs, so a later change to that block cannot break them unnoticed. Change-Id: I1e9a7fc3a96c92b8fac0ee06abe2eff8160aabc3
TKkusa
force-pushed
the
python-solution-per-case
branch
from
November 22, 2026 05:37
1bc3700 to
409fa1b
Compare
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.
Problem and behavior
The Python driver ran every test case against one
Solutionbuilt before the case loop, so an answer that keeps state onselfstarted each case with what the earlier cases left behind. On Grid Segment Net Yield, the answer in the issue, withself.bestset in__init__, showedTest results · 2/6, every case after the second returning 42; it now passes 6 of 6, as it already did in C++. An__init__that raises, such asself.memo = {}[0], used to read asCould not find bestRouteYield in your code - keep the starter signature.; each case now fails withKeyError: 0.Approach
The driver keeps its setup check that
Solutiondefines the entry method and builds the instance inside each case'stry, as the C++ and Java harnesses inweb/compiler-explorer.jsalready do. Class judges and answers written as a plain function take the same path as before, and a test pins each. Another test makes sure each case runs on an instance__init__built for it alone: every case reports how many times__init__has run, whetherselfis the newest object it ran on, and the attributesselfalready had. An answer that does heavy work in__init__now repeats it for every case, inside the same 5 s run budget and counted in that case'stimeMs, which is also how C++ and Java construct.pythonDriveris exported fromweb/runners.jssotests/browser/python-driver.test.jscan run it on CPython fromnode --test, as suggested on #783. The tests skip only when the interpreter,python3or the onePYTHONnames, is missing; one that is there but does not start, exits nonzero or hangs fails them with what--versionshowed. A fix for #783 would need the same export, so whichever change lands second rebases onto the other. The fresh-state test also asserts that the judge's cases still expose a shared instance, so reordering the bank's cases cannot leave it passing on the old driver.Validation
node --test tests/browser/python-driver.test.js:# pass 6,# fail 0. Before the fix the three tests of per-case state and construction fail (cases 3 to 6 got 42; a setup error instead ofKeyError: 0). A driver that shares one instance, hands each case acopy.copyorcopy.deepcopyof it, calls__init__on it again (with or without clearing its__dict__), builds every instance before the loop, skips__init__, or repeats, stops at or returns the first constructor error fails at least one test. WithPYTHONpointing at a missing interpreter all six skip; with a non-executable one or/bin/falseall six fail with the probe's message.runBrowserTests: the issue's answer passes 6/6 and the raising__init__givesKeyError: 0in every case. I also checked both by hand in an offline Practice interview../scripts/test.sh browserat the first head (e3d54427, the sameweb/runners.js):pass 2224,fail 0, with 1393 tests skipped because Playwright 1.65's Chromium was not installed here. The suites that run Python in the page (runners,graph-clone-identity,candidate-cases,task-runner,specialized-tree-cycles) and the new file, rerun with an installed Playwright 1.64.1 Chromium:pass 192,fail 0, 22 Java skips../scripts/test.sh portable:review-memory-tests,git-hooksandshell-syntaxfail here identically on a cleanmain(noghin WSL, commentflow, shfmt and ruff not installed, shellcheck 0.11.0)../scripts/test.sh rustpasses here. Not run: Java (nojavac).Close #799
Summary by cubic
Builds a fresh
Solutionfor each Python test case so answers that keep state onselfno longer leak state between cases, matching what C++ and Java already do. On Grid Segment Net Yield an answer that setself.bestin__init__previously passed 2 of 6 cases, returning 42 after the second case; it now passes 6 of 6. A constructor that raises now fails each case with the real error (KeyError: 0) instead ofCould not find bestRouteYield in your code - keep the starter signature.Solution()construction inside each case'stry; the setup check that the entry method exists is unchanged.__init__built for it alone: each case reports the construction count, whether it's the newest instance, and pre-existing attributes — a driver that shares, copies, re-initializes, or prebuilds an instance fails it.pythonDriverfromweb/runners.jssotests/browser/python-driver.test.jscan run it on CPython, skipping whenpython3is absent. The new tests also cover the paths the fix keeps: a missing entry method is still a setup error, class judges keep one shared instance per case, and plain-function answers still run.Closes #799.
Written for commit 409fa1b. Summary will update on new commits.