Repository navigation
0.4.0 pre-release: quote_blocks without deepcopy; LegaldownDeprecationWarning - #101
Merged
Merged
Conversation
…nWarning quote_blocks deep-copied the cached reading of a quote, which recursed once per nesting level and raised RecursionError for a list nested about 62 deep inside a quote — input the parser accepts (MAX_LIST_DEPTH 64). Found by PactTrack's migration to 0.4.0. It now reads the quote again, uncached (_read_quote_content), so the blocks are still the caller's to change and the cache is untouched; drafting_note_blocks builds on it. tests/test_deep_nesting.py runs every public path (parse, validate with and without final, serialize, the dict round trip, layout, line_of, body_layout, iter_document_directives, find_markers, block_fragments, the quote readers, code_content, template assembly) on lists, quotes and their mixes at and past the parser's limits. Every deprecation legaldown raises is now a LegaldownDeprecationWarning (a DeprecationWarning subclass, exported from legaldown), so one filter catches them all; the README says how (warnings.simplefilter, or pytest filterwarnings — Python's -W cannot name a package's category). 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.
Two fixes found while migrating PactTrack (ForLegalAI/PactTrack#106) to the unreleased 0.4.0.
quote_blocksRecursionErrorThe bug:
legaldown.syntax.quote_blocksdeep-copied the cached reading of a quote.copy.deepcopyrecurses once per nesting level, so it raisedRecursionErrorfor a list nested about 62 levels inside a quote. The parser accepts that input (MAX_LIST_DEPTHis 64).The fix:
quote_blocksnow reads the quote again without the cache, through_read_quote_content, the uncached body ofquote_content. The caller still gets blocks of its own that it may change, and the cache is left alone.drafting_note_blocksis built onquote_blocks, so it is fixed too.Tests: the new
tests/test_deep_nesting.pyhas 100 tests. They run every public path on lists, quotes and mixes of both at and past the parser's limits, from 64 to 70 nested lists and 16 to 20 nested quotes. The paths are:parse, andvalidatewith and withoutfinal;serialize, and the dict round trip;layout,line_ofandbody_layout;iter_document_directives,find_markersandblock_fragments;code_content;Before the fix only
quote_blocksanddrafting_note_blocksfailed. Every path also passes with the recursion limit lowered to 600.One warning category for every deprecation
LegaldownDeprecationWarning, aDeprecationWarningsubclass exported fromlegaldown. That coversparse_document,serialize_document,validate_document, the importer keyword arguments,assemble,template_questionsandneeded_questions.stacklevel=2the warnings are attributed to the caller's module, and their messages don't share a prefix, so no single filter caught them all. ExistingDeprecationWarningfilters still match.warnings.simplefilter("error", LegaldownDeprecationWarning)and pytest'sfilterwarnings = ["error::legaldown.LegaldownDeprecationWarning"]. Python's own-Woption andPYTHONWARNINGScannot name a category defined in a package. That was checked on Python 3.11, 3.12 and 3.13.Verification
ruffis clean.main.🤖 Generated with Claude Code
https://claude.ai/code/session_013WmBAc5T7UCKVdpUmg9qxz
Generated by Claude Code