Repository navigation
Fix three bugs in the reference Python programs - #54
Closed
scottchristensen9-lgtm wants to merge 1 commit into
Closed
scottchristensen9-lgtm wants to merge 1 commit into
scottchristensen9-lgtm wants to merge 1 commit into
Conversation
- shortest_path_length: insert_or_update overwrote a heap entry in place, which breaks the heap order when a distance drops; re-heapify after it. - wrap: when the remaining text starts with a space, rfind returns 0 and the loop never advances; emit the space as its own line. - node.py: the [] defaults were one list shared by every Node, so adding a successor to one default-built node added it to all of them. The successor/successors/predecessors methods were also shadowed by the attributes of the same name and could never be called; removed. Adds a repro test for each. pytest --correct passes; buggy-mode outcomes are unchanged for every existing test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014ko1H1xkFYEG8XajqP9FPS
Owner
|
I'm going to close this without reading. First, as a general policy: to accept an AI written PR from a stranger, I at least expect the contributor to put as much effort into preparing it as I would into reviewing it, and at least to give a human-written PR description. Second: it seems unlikely any errors of this type have persisted in such shallow code after so many eyeballs have been on it. Third: at first glance, without having tried to understand, this sounds like exactly the kind of thing AIs get wrong. AIs are infamous for reporting as "issues" when a program doesn't handle illegal input. Feel free to reopen after human review if you believe this issue is genuine. |
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.
While running the Python test suite I found three bugs that are still present in
correct_python_programs/(and the sharednode.pyhelpers). None of them are the seeded bugs, and this PR leavespython_programs/alone apart from its copy ofnode.py, which has no seeded bug.1.
shortest_path_length: a distance update can break the heap.insert_or_updateoverwrites an entry in place (the comment says heapq keeps the order, but it doesn't). When a node's distance drops below its parent's in the heap,heappopreturns the wrong node. Graph:a->b 1, a->c 8, a->d 7, b->c 2, c->d 2. The answer is 5 (a, b, c, d), but the reference returns 7 becausedis popped before the updatedc. Fix:heapifyafter the replacement.2.
wrap: hangs when the remaining text starts with a space.wrap("hello world", 5)cuts"hello", thenrfind(' ', 0, 6)on" world"returns 0, so the loop appends""forever. Fix: whenend == 0, emit the space as its own line, which gives["hello", " ", "world"]. That output keeps the docstring's rules: every line fits, spaces are preserved, and the lines join back into the original.3.
node.py: default lists are shared by every node.successors=[](and the other three) is one list object for everyNodebuilt without that argument, so appending to one node's default list changes all of them. On master, adding a test that doesNode("a").successors.append(...)makes five unrelated graph tests fail (test_shortest_path_length2 and 4,test_topological_ordering1 to 3). Thesuccessor(),successors()andpredecessors()methods in the program copies were also hidden by the attributes of the same name, so they could never be called. I removed them.Tests. Each fix comes with a repro test:
test5intest_shortest_path_length.py,test_wrap_leading_spaceintest_wrap.py, and a newtest_node.py. All three fail on master (wrong distance, timeout, shared list) and pass here.pytest --correct --timeout=20 python_testcases -k "not knapsack": 270 passed, 1 skipped. Master gives 267 passed; the 3 extra are the new tests.--timeout=5, same filter, new tests excluded): all 264 outcomes match master, so benchmark scoring is unchanged.🤖 Generated with Claude Code
https://claude.ai/code/session_014ko1H1xkFYEG8XajqP9FPS