0.4.0: save(document) and serialize(document); serialize_document deprecated - #99
Merged
Merged
Conversation
… deprecated Writing a document now mirrors reading it: `load(path)` → edit → `save(document)` writes it back to `document.path` (or to a given path, which the document then lives at: `path` and `filename` follow, as after `load`). The write is atomic — a temporary file beside it, moved into place — writes through a symbolic link, keeps the file's permissions, and creates missing directories; the text is UTF-8, LF, no BOM. The atomic writer `--save-answers` used moves from cli.py to files.py and serves both. `serialize(document)` is the text, the inverse of `parse`. `serialize_document` still works, with a DeprecationWarning; deprecated since 0.4.0, removed in 0.5.0, like `parse_document` and `validate_document`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013WmBAc5T7UCKVdpUmg9qxz
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.
Writing a document now mirrors reading it. This is the last workflow piece of the 0.4.0 API simplification.
Changes
save(document, path=None) -> Pathpath, or, when no path is given, back todocument.path(whereloadfound it). A document fromparse(text)or built in code has no path, so it getsValueErroruntil one is passed.load:document.pathanddocument.filenamefollow it. That matters becausevalidatereads an amended original or attachment definitions from besidedocument.path, and diagnostics name the filename. On failure, both are unchanged.serialize(document) -> strparse.serialize_documentstill works but raises aDeprecationWarning. Likeparse_documentandvalidate_document, it is deprecated since 0.4.0 and will be removed in 0.5.0.Shared atomic writer
--save-answersalready used moves fromcli.pytofiles.write_atomically, which is not exported, and now serves both. The CLI's behaviour is unchanged.Docs
load→ edit →save(document), with a paragraph on whatsaveguarantees. The quick start printsserialize(document), so running it does not rewrite your file.serialize_document.Verification
tests/test_save.py, plus the deprecation test).ruffis clean.tests/test_save.pycovers:ValueErrorwithout a path,strand PathLike paths, and creating directories;validatereading from beside the new path;main.serialize.serialize_documentremains only in the deprecated wrapper, its export, the deprecation note and its test.🤖 Generated with Claude Code
https://claude.ai/code/session_013WmBAc5T7UCKVdpUmg9qxz
Generated by Claude Code