Skip to content

Fix Subscript rendering in both printing paths - #164

Merged
ESultanik merged 4 commits into
masterfrom
154-subscript-rendering
Sep 9, 2026
Merged

ESultanik merged 4 commits into
masterfrom
154-subscript-rendering

Conversation

@ESultanik

Copy link
Copy Markdown
Collaborator

Closes #154

Subscript nodes have two printing paths, and each had its own defect. They are mutually exclusive at runtime: PyDiffFormatter.print_Subscript shadows ast.Subscript.print whenever PyDiffFormatter is in play, and the node's own print only runs as the tree.py fallback when no formatter resolves the type. That is why both defects went unnoticed.

  • graphtage/ast.py: Subscript.print called self.slice.write(printer). TreeNode has no write method, so the fallback path emitted a[ and then raised AttributeError: 'IntegerNode' object has no attribute 'write'. It now calls self.slice.print(printer), matching the surrounding lines.
  • graphtage/pydiff.py: PyDiffFormatter.print_Subscript wrote an opening bracket where the closing one belongs, so an unedited a[1] rendered as a[1[.

The two regression tests in test/test_pydiff.py reach each path deliberately: one calls the node's print method directly, the other goes through PyDiffFormatter. Assertions stay at the unedited-tree level, because a diff of a[1] against a[2] reaches neither path (DataClassEdit has no print() override, issue #150).

Validation

Both new tests were run against the unfixed source first and each failed on its own defect: test_subscript_node_print with AttributeError: 'IntegerNode' object has no attribute 'write', and test_subscript_formatter_print with AssertionError: 'a[1]' != 'a[1['. Both pass after the fix.

  • ruff check graphtage test docs bindist: passes
  • pytest: 142 passed
  • make -C docs html SPHINXOPTS="-W --keep-going": build succeeded
  • uv lock --check: unchanged by this PR; no dependency edits were made

🤖 Generated with Claude Code

https://claude.ai/code/session_01GypKU5KdLfs2Cf8kS2TzJa

YusufT0 and others added 4 commits September 9, 2026 16:58
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
@ESultanik
ESultanik merged commit ece238a into master Sep 9, 2026
12 checks passed
@ESultanik
ESultanik deleted the 154-subscript-rendering branch September 9, 2026 14:42
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.

Subscript nodes render incorrectly in both printing paths

2 participants