Fix Subscript rendering in both printing paths - #164
Merged
Merged
Conversation
Subscript nodes have two printing paths, and each carried its own defect. Subscript.print, the fallback that GraphtageFormatter.print uses when no formatter resolves the node type, called self.slice.write(printer). TreeNode has no write method, so printing any subscript through that path emitted the opening bracket and then raised AttributeError. The surrounding lines already call print on the child nodes, so the call now matches them. PyDiffFormatter.print_Subscript wrote an opening bracket where the closing one belongs, rendering a[1] as a[1[. Because the formatter shadows the node's own print method whenever PyDiffFormatter is in play, the two defects never surfaced together, so the regression tests reach each path deliberately: one calls the node's print method directly, the other goes through the formatter. Closes #154 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GypKU5KdLfs2Cf8kS2TzJa
fix: fixed the #154 bugs.
…ring # Conflicts: # test/test_pydiff.py
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.
Closes #154
Subscriptnodes have two printing paths, and each had its own defect. They are mutually exclusive at runtime:PyDiffFormatter.print_Subscriptshadowsast.Subscript.printwheneverPyDiffFormatteris in play, and the node's ownprintonly runs as thetree.pyfallback when no formatter resolves the type. That is why both defects went unnoticed.graphtage/ast.py:Subscript.printcalledself.slice.write(printer).TreeNodehas nowritemethod, so the fallback path emitteda[and then raisedAttributeError: 'IntegerNode' object has no attribute 'write'. It now callsself.slice.print(printer), matching the surrounding lines.graphtage/pydiff.py:PyDiffFormatter.print_Subscriptwrote an opening bracket where the closing one belongs, so an unediteda[1]rendered asa[1[.The two regression tests in
test/test_pydiff.pyreach each path deliberately: one calls the node'sprintmethod directly, the other goes throughPyDiffFormatter. Assertions stay at the unedited-tree level, because a diff ofa[1]againsta[2]reaches neither path (DataClassEdithas noprint()override, issue #150).Validation
Both new tests were run against the unfixed source first and each failed on its own defect:
test_subscript_node_printwithAttributeError: 'IntegerNode' object has no attribute 'write', andtest_subscript_formatter_printwithAssertionError: 'a[1]' != 'a[1['. Both pass after the fix.ruff check graphtage test docs bindist: passespytest: 142 passedmake -C docs html SPHINXOPTS="-W --keep-going": build succeededuv lock --check: unchanged by this PR; no dependency edits were made🤖 Generated with Claude Code
https://claude.ai/code/session_01GypKU5KdLfs2Cf8kS2TzJa