-
Notifications
You must be signed in to change notification settings - Fork 119
fix: markdown export under -O #462
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Guiforge
wants to merge
4
commits into
docling-project:main
from
Guiforge:fix/markdown-optimized-mode-460
Closed
fix: markdown export under -O #462
Guiforge
wants to merge
4
commits into
docling-project:main
from
Guiforge:fix/markdown-optimized-mode-460
+14
−6
Conversation
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
Avoid assignment-in-assert during list marker normalization (issue docling-project#460).
Contributor
|
✅ DCO Check Passed Thanks @Guiforge, all your commits are properly signed off. 🎉 |
Merge ProtectionsYour pull request matches the following merge protections and will not be merged until they are valid. 🟢 Enforce conventional commitWonderful, this rule succeeded.Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/
|
Member
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Delete test/test_markdown_optimized_mode.py. The test targeted markdown serialization under Python -O and has been removed as obsolete.
…ail.com> I, Guillaume Pouyat <[email protected]>, hereby add my Signed-off-by to this commit: a9ce24f I, Guillaume Pouyat <[email protected]>, hereby add my Signed-off-by to this commit: 88b8996 Signed-off-by: Guillaume Pouyat <[email protected]>
…ail.com> I, Guillaume Pouyat <[email protected]>, hereby add my Signed-off-by to this commit: a9ce24f I, Guillaume Pouyat <[email protected]>, hereby add my Signed-off-by to this commit: 88b8996 Signed-off-by: Guillaume Pouyat <[email protected]>
Author
|
I closed; it seems solved. 👍 (#456) |
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.
Fix Markdown export under Python optimized mode (-O)
Context
Issue: docling-project/docling-core#460
Markdown export could crash when running Python with optimizations enabled (e.g.
python -OorPYTHONOPTIMIZE=1).Symptom
UnboundLocalError: cannot access local variable 'list_group' where it is not associated with a valueThis surfaced during Markdown serialization of list items.
Root cause
In
docling_core/transforms/serializer/markdown.py(Markdown list item serialization),list_groupwas assigned via the walrus operator inside anassert:assert item.parent and isinstance((list_group := item.parent.resolve(doc)), ListGroup)Under
-O, Python stripsassertstatements entirely, so the assignment never executes. Since Python still treatslist_groupas a local variable in the function, later references tolist_groupraiseUnboundLocalError.(Conceptually the same as Ruff rule RUF018: assignment in assert.)
Fix
assert.list_groupexplicitly (outside ofassert) and guard access with anis not Nonecheck.ListGroup, fall back to the safe Markdown marker-rather than crashing.This preserves existing behavior for valid documents and prevents optimized-mode crashes.
Tests
test/test_markdown_optimized_mode.pywhich spawns a subprocess withsys.executable -Oand callsDoclingDocument.export_to_markdown()on a minimal document that triggers list marker normalization.Notes