Refresh the library, builder, printing, and how-it-works docs - #145
Merged
Merged
Conversation
The bipartite matching description covered only `--dict-strategy match`, which stopped being the default in PR #51. Describe `auto`, `match`, and `none`, and say which one is the default. Add a section on `--ignore-list-order`, which builds `UnorderedListNode` rather than `ListNode`, and give the complexity trade-off from the `BuildOptions.ignore_list_order` docstring. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GypKU5KdLfs2Cf8kS2TzJa
The quoted condition for choosing an edit over a node was missing the `isinstance(node_or_edit, EditedTreeNode)` guard, and the raw bounds comparison it showed has been replaced by `Edit.has_non_zero_cost()`, which tightens bounds in a loop rather than doing one cheap check. Add sections on `Printer(quiet=...)`, `NULL_PRINTER`, `StatusWriter`, and `enable_ansi_support()`: importing graphtage no longer calls `colorama.init()` or replaces `sys.stdout`. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GypKU5KdLfs2Cf8kS2TzJa
Every code sample on this page failed as written: - `graphtage.dataclasses.DataClass` does not exist; the class is `DataClassNode`. - `@Build.builder(Bar)` is a typo for `@Builder.builder(Bar)`. - The last two methods were missing `self`, so `Builder.expand` and `Builder.build` raised `TypeError` when calling them. - `StringNode`, `ListNode`, and `BasicBuilder` were used but never imported. - `ListNode` stores a tuple, so its repr is `ListNode((...))`, and `StringNode`'s repr uses single quotes. Repoint the dangling `graphtage.Builder.builder`, `graphtage.Builder.expander`, and `graphtage.SequenceNode` cross references at their real modules, use `:meth:` for the two methods, make the inline-only `CustomNode` reference a literal, and correct `instanceof` to `isinstance`. Add sections on data class slots and `post_init()`. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GypKU5KdLfs2Cf8kS2TzJa
PR #132 put removals before insertions in the edit tie-break order, so every output block on this page was stale. Rerun the whole session and paste the real output. The last element of the pydiff example is now a `Replace` rather than an insert and remove pair. Delete the stray `from_node.diff(to_node)` line, which used two names the session never defines, and correct `instanceof` to `isinstance`. Read the default printer through `printer.get_default_printer()` rather than the `printer.DEFAULT_PRINTER` module attribute, and use the `p` the examples already bind. Add sections on `BuildOptions`, `pydiff.diff()`, `pydiff.build_tree()`, and diffing Python source through `pydiff.ast_to_tree`. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GypKU5KdLfs2Cf8kS2TzJa
Collaborator
Author
|
The code defects noted in the PR description are now tracked:
|
Collaborator
Author
|
Correction to my earlier comment: #150 is not a missing formatter. That does not change anything in this PR: the AST example still needs to avoid an edited call until #150 lands. |
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.
Refreshes the four prose pages that document Graphtage as a library. The last new prose in
docs/landed 2024-01-07, anddocs/howitworks.rstanddocs/printing.rsthad not changed since May 2020.What was broken
docs/library.rstget_all_editsnow yields theStringEditbefore theRemove, the JSON key renders as~~foo~~++bar++, and the YAML key likewise. The last element of the pydiff example is now a singleReplace(4 -> "four") rather than an insert and remove pair, and the custom-class example rendersba~~z~~++k++.>>> from_node.diff(to_node)line used two names the session never defines. The session bindsfrom_treeandto_tree, and the real call was the next line. Pasting the block raisedNameError.:func:instanceof`` is not a Python builtin; it isisinstance.printer.DEFAULT_PRINTERdirectly.graphtage/printer.pysays to read it throughget_default_printer(), becauseset_default_printerrebinds the module attribute. The examples also boundas pand then ignored it.docs/builders.rstFive separate defects made the examples fail:
graphtage.dataclasses.DataClassdoes not exist. The class isDataClassNode, so the prose cross reference was dangling and the code sample raisedNameError.@Build.builder(Bar)is a typo for@Builder.builder(Bar).self.Builder.expandcallsexpander(self, node)andBuilder.buildcallsbuilder(self, node, children), so both raisedTypeError. The earlier examples on the same page already tookself.graphtage.Builder.builder,graphtage.Builder.expander, andgraphtage.SequenceNodewere dangling cross references.BuilderandSequenceNodeare not hoisted into the top-level namespace. They are also methods, so they now use:meth:.StringNode,ListNode, andBasicBuilderwere used but never imported, and two reprs were wrong:ListNodestores a tuple, so it printsListNode((...)), andStringNode's repr uses single quotes.docs/printing.rstThe quoted condition for choosing an edit over a node was missing the
isinstance(node_or_edit, EditedTreeNode)guard, and the raw bounds comparison it showed was replaced byEdit.has_non_zero_cost(), which tightens bounds in a loop before comparing. The rest of the protocol description checked out againstgraphtage/tree.pyand is unchanged.docs/howitworks.rst"Dicts are matched by solving the minimum weight matching problem on the complete bipartite graph" describes
--dict-strategy match, which stopped being the default in PR #51. The default isauto.What was added
docs/library.rst: sections onBuildOptions(used indocs/filetypes.rstsignatures but never explained),pydiff.diff(),pydiff.build_tree(), and diffing Python source throughpydiff.ast_to_treeandASTBuilder.docs/builders.rst: sections on data class slots (type enforcement, theTypeErroron redefining an ancestor's slot, subscripted generics being skipped) andpost_init().docs/printing.rst: sections onPrinter(quiet=...),NULL_PRINTER,StatusWriter, and the PR Keep forced color when stdout is redirected #130enable_ansi_support()split. Importinggraphtageno longer callscolorama.init()or replacessys.stdout.docs/howitworks.rst: all three dict strategies, and a section on--ignore-list-orderandUnorderedListNode.Verification
library.rstsession end to end.sphinx-build -W --keep-going -E -b html docs docs/_build/htmlproduces no new warnings. Two warnings remain on this branch, both pre-existing onmasterand both outside these files: duplicate object descriptions forgraphtage.Edit.from_nodeandgraphtage.Edit.initial_bounds, caused bygraphtage/tree.pycarrying both anAttributes:docstring section and inline attribute docstrings for the same two names.ruff check graphtage test docs bindistpasses.Code defects found, not fixed
No
graphtage/*.pysource file was touched. These are reported for separate issues:BuildOptions.__init__takes the keywordcheck_for_cyceswhile the attribute ischeck_for_cycles(graphtage/graphtage.py:1017and:1051). Already known.DataClassNode.post_init()never runs for the class being instantiated.__init__iteratesself._DATA_CLASS_ANCESTORS, which excludesclsitself, so apost_initdefined on a class only runs when a subclass of it is instantiated. The page documents the actual behavior rather than the intended one.DataClassNode.printusesFore.Yellow, which does not exist (coloramaspells itFore.YELLOW). Any call raisesAttributeError.graphtage/ast.pySubscript.printcallsself.slice.write(printer)instead ofself.slice.print(printer).graphtage/pydiff.pyPyDiffFormatter.print_Subscriptwrites"["twice; the closing bracket should be"]".graphtage/pydiff.pyPyObjAttribute.__init__testsisinstance(object, StringNode)against the builtinobjectrather thanself.object, so the branch never fires.ASTBuilderhas no builder forast.Import, soast_to_tree(ast.parse("import os"))raisesNotImplementedError. Onlyast.ImportFromis handled.DataClassEdit, so an editedAssignment,Call, orImportfalls through to the generic compound-edit printer.x = foo(1, 2)againstx = foo(1, 2, 3)renders as[x]foo[1,2,++3++]instead of Python source. Unedited AST trees print correctly.🤖 Generated with Claude Code
https://claude.ai/code/session_01GypKU5KdLfs2Cf8kS2TzJa