Skip to content

Fix and speed up complex Word numbering resolution - #137

Open
JasonRJFleischer wants to merge 6 commits into
merge-allfrom
jason/num-order-fixes
Open

Fix and speed up complex Word numbering resolution#137
JasonRJFleischer wants to merge 6 commits into
merge-allfrom
jason/num-order-fixes

Conversation

@JasonRJFleischer

@JasonRJFleischer JasonRJFleischer commented Jul 28, 2026

Copy link
Copy Markdown

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

Mostly LLM Generated

Fixes correctness issues in Word numbering resolution and speeds up large-document numbering reads.

  • Resolve multi-component lvlText labels from per-level numbering state instead of parsing the previous rendered label.
  • Keep unrelated lists' startOverride values from affecting independent counters.
  • Cache numbering definitions, start overrides, paragraph numbering properties, and styles during numbering lookup.
  • Reuse those caches when rendering multi-part numbering labels.
  • Bump package version to 0.8.10.41.

See tests in Platform: https://github.com/openlawlibrary/platform/pull/6224

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

Compute each %N in multi-component lvlText from the matching level's
counter and start value instead of splicing the previous paragraph's
rendered label. This matches Word's parent-level numbering behavior and
avoids crashes when the prior paragraph uses a different list format.
Do not apply a preceding list's startOverride when the current list has
its own explicit start. This keeps independent list instances separate
while preserving continuation across re-keyed section lists.
Cache abstractNum and startOverride lookups on CT_Numbering, invalidating
on add_num, to avoid repeated numbering XML scans during paragraph
numbering.
Cache resolved paragraph numbering properties and styles during
get_num_for_p, invalidating when numbering assignments change. This
removes repeated pPr/style resolution while preserving existing skip
behavior.
Use cached paragraph style and startOverride lookups inside value_at_ilvl
so multi-component lvlText rendering stays on the same fast path as
single-level numbering.
@JasonRJFleischer JasonRJFleischer changed the title numbering order fixes and performance updates Fix and speed up complex Word numbering resolution Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant