Implement NumberingPart.new() to auto-create an empty numbering part - #1607
Draft
xtaypp wants to merge 2 commits into
Draft
Implement NumberingPart.new() to auto-create an empty numbering part#1607xtaypp wants to merge 2 commits into
xtaypp wants to merge 2 commits into
Conversation
DocumentPart.numbering_part documents that it creates an empty numbering part when one is not present, but NumberingPart.new() raised NotImplementedError, so opening a .docx without a numbering part and accessing the numbering part failed. Implement NumberingPart.new(package) mirroring the StylesPart/SettingsPart/CommentsPart factories, backed by a new minimal default-numbering.xml template, and pass the package from DocumentPart.numbering_part.
NumberingPart.new() takes the owning package, mirroring the package-taking factories SettingsPart.default / CommentsPart.default / StylesPart.default. Update the DocumentPart.numbering_part test to assert NumberingPart.new is called with the package, and add a NumberingPart.new() construction test mirroring the default-part tests in test_settings/test_comments/test_styles (partname, content type, package, w:numbering root element, empty content).
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.
Summary
DocumentPart.numbering_partis documented to "create an empty numbering part if one is not present", butNumberingPart.new()raisedNotImplementedError. Opening a.docxthat has no numbering part (noword/numbering.xml/ no numbering relationship) and then accessing the numbering part therefore failed instead of auto-creating it.Root cause
NumberingPart.new()was an unimplemented stub. Unlike the sibling part factories (StylesPart.default(),SettingsPart.default(),CommentsPart.default()), it never constructed a part, and there was no default template for an empty numbering part.Changes
src/docx/templates/default-numbering.xml— a minimal numbering part containing only the root<w:numbering>element.NumberingPart.new(package)mirroring the other part factories: partname/word/numbering.xml, content typeCT.WML_NUMBERING, root element parsed from the new default template.DocumentPart.numbering_part: passself.packagetoNumberingPart.new()on the auto-create path.The template is already covered by
MANIFEST.in(graft src/docx/templates), so it ships in the package like the other default parts.Validation
master..docxwithout a numbering part and accessingnumbering_partnow returns aNumberingPartwhose root isCT_Numbering(0 definitions); saving persistsword/numbering.xmlwith the registered content type and relationship, and reopening reads it back..docxfiles (forcing the auto-create path) passed with no failures.This adds no new public API; it fulfills behavior the property already documents.