Skip to content

Abstract num and table numbering fixes#136

Merged
JasonRJFleischer merged 3 commits intomerge-allfrom
jason/num-fixes
Apr 9, 2026
Merged

Abstract num and table numbering fixes#136
JasonRJFleischer merged 3 commits intomerge-allfrom
jason/num-fixes

Conversation

@JasonRJFleischer
Copy link
Copy Markdown

Description (e.g. "Related to ...", "Closes ...", etc.)

python-docx 0.8.10.40 upgrades:

uses the abstract num to determine identity: paragraphs with different numIds but the same abstractNumId are counted as one continuous list, while startOverride is still respected for intentional restarts

traverses the full XML tree, including tables, to determine current numbering, so it no longer skips table nums with the same abstract nums

Code review checklist

  • Private platform tests at core/tests/test_python-docx are updated and passing
  • If this change is going to be deployed on Cloudsmith after merge, python-docx version number should be increased

Replace p.itersiblings(preceding=True) with iter_preceding_paragraphs()
which walks up the XML tree and yields paragraphs across nesting
boundaries (table cells, rows, etc.). Previously, numbered paragraphs
inside tables were invisible to the sibling-only iteration, causing
incorrect numbering counts.
Add same_abstract_num() to compare whether two numIds resolve to the
same abstract numbering definition. This replaces pStyle.val comparison
which could false-positive when unrelated lists share a generic paragraph
style such as "ListParagraph", causing incorrect numbering counts.

A startOverride on either numId signals an intentional restart (new list
instance from the same template), so same_abstract_num returns False in
that case to preserve reset behavior.
@JasonRJFleischer JasonRJFleischer merged commit 997f043 into merge-all Apr 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants