Repository navigation
Conversation
|
✅ DCO Check Passed Thanks @chrikrah, all your commits are properly signed off. 🎉 |
Merge Protections🟢 Merge protection satisfied — ready to merge. Show 1 satisfied protection🟢 Enforce conventional commitMake sure that we follow https://www.conventionalcommits.org/en/v1.0.0/
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
4a9b14e to
30857fd
Compare
ceberam
left a comment
There was a problem hiding this comment.
Thanks @chrikrah for your contribution!
Both fixes are correct. The _add_figure_captions change properly defaults caption to "" instead of None, preventing the literal string "None" from appearing after the label in the f-string. The _add_tables change applies the same or "" guard already used at line 638 for <etal>. Scope is narrow — no regressions, no performance impact.
I have added a minor style comment below.
In addition, please review the inline comments. The three-line comment before caption: str = "" in _add_figure_captions explains why None was not used — that is authoring context, and the type annotation already says it all. Remove it. The single-line comment in _add_tables is more defensible (lxml's None-on-empty-element is non-obvious), but trim the second clause to remove the fix-reasoning, for instance: # lxml sets .text to None for an empty element; fall back to "".
| def _caption_texts(doc: DoclingDocument) -> list[str]: | ||
| return [ | ||
| t.text for t in doc.texts if str(getattr(t, "label", "")).endswith("caption") | ||
| ] |
There was a problem hiding this comment.
All items from doc.texts are TextItem instances and always have a .label field. The project coding standards prohibit broad getattr(...)/hasattr(...) patterns. The rest of the test file uses direct attribute access. Replace with:
| def _caption_texts(doc: DoclingDocument) -> list[str]: | |
| return [ | |
| t.text for t in doc.texts if str(getattr(t, "label", "")).endswith("caption") | |
| ] | |
| def _caption_texts(doc: DoclingDocument) -> list[str]: | |
| return [t.text for t in doc.texts if t.label == DocItemLabel.CAPTION] |
Three points from ceberam, all about how the change reads: - The comment before `caption: str = ""` in `_add_figure_captions` said what the annotation already says, so it is gone. - The comment in `_add_tables` is down to the one line that carries the fact a reader cannot see: lxml sets `.text` to None for an empty element. - `_caption_texts` in the test compares `t.label` to `DocItemLabel.CAPTION` directly. The `getattr` and the string suffix match were defensive for no reason; `DocItemLabel` was already imported. No behaviour change. 59 passed in tests/test_backend_jats.py, and reverting jats_backend.py alone to 815f34a still fails both new cases (2 failed, 57 passed), so the direct comparison pins the fix as well as the old helper. Signed-off-by: Christopher Krah <48338417+chrikrah@users.noreply.github.com>
|
All three taken, in The three-line comment in The # lxml sets .text to None for an empty element; fall back to "".And return [t.text for t in doc.texts if t.label == DocItemLabel.CAPTION]That file already imports
|
…aptions
Two places write None into text a reader sees.
_add_figure_captions sets caption = None when a <fig> has a <label> and no
<caption>, which is legal and common for a numbered but uncaptioned figure. The
f-string at :917 then renders the four characters None straight after the label:
<fig><label>Figure 1.</label><graphic/></fig> -> 'Figure 1.None'
_add_tables reads table["label"] = node.xpath("label")[0].text without a
guard. An empty <label/> has .text of None in lxml, so a table with neither a
real label nor a caption still produces a caption item reading None:
<table-wrap><label/><table>...</table></table-wrap> -> 'None'
Both now keep the empty-string default the surrounding code already uses, the
same way :634 reads etal_node[0].text or DEFAULT_TEXT_ETAL.
Tests: 59 passed in tests/test_backend_jats.py. Two new cases; reverting
jats_backend.py alone fails both. No groundtruth file changes, and no committed
JATS groundtruth contains the string None today, so no current fixture reaches
either path.
Signed-off-by: Christopher Krah <48338417+chrikrah@users.noreply.github.com>
Three points from ceberam, all about how the change reads: - The comment before `caption: str = ""` in `_add_figure_captions` said what the annotation already says, so it is gone. - The comment in `_add_tables` is down to the one line that carries the fact a reader cannot see: lxml sets `.text` to None for an empty element. - `_caption_texts` in the test compares `t.label` to `DocItemLabel.CAPTION` directly. The `getattr` and the string suffix match were defensive for no reason; `DocItemLabel` was already imported. No behaviour change. 59 passed in tests/test_backend_jats.py, and reverting jats_backend.py alone to 815f34a still fails both new cases (2 failed, 57 passed), so the direct comparison pins the fix as well as the old helper. Signed-off-by: Christopher Krah <48338417+chrikrah@users.noreply.github.com>
c9f9b96 to
dab5b14
Compare
|
Rebased onto Revert
|
Two places in the JATS backend write
Noneinto text a reader sees._add_figure_captionssetscaption = Nonewhen a<fig>carries a<label>and no<caption>. That combination is legal, and common for a numbered but uncaptioned figure. The f-string at:917then renders the four charactersNonestraight after the label:_add_tablesreadstable["label"] = node.xpath("label")[0].textwith no guard at:1175. An empty<label/>has.textofNonein lxml, so a table with neither a real label nor a caption still produces a caption item:After the change the first reads
Figure 1.and the second emits no caption item at all.The file already has the pattern
:634readsetal_node[0].text or DEFAULT_TEXT_ETAL. Both sites now keep the empty-string default the surrounding code already uses.Tests
Two new cases. Revert
jats_backend.pyalone, keep them, and both fail.No groundtruth file changed.
grep -rl None tests/data/jats/groundtruth/returns nothing, so no committed fixture reaches either path today, which is why this went uncaught.Scope
The
<fig>case needslabelpresent andcaptionabsent. A figure with both, or with neither, already rendered correctly. The table case needs an empty<label/>element rather than a missing one.Duplicate search
Three open pull requests touch
docling/backend/xml/jats_backend.py: #4272, #3891 and #3791. None mentions_add_figure_captions,table["label"]orcaption = None.gh issue list --state all --search "jats caption None"andgh pr list --state all --search "jats figure caption"return nothing covering this.Checklist:
No document describes how a caption is composed from
<label>and<caption>.The change corrects existing output rather than adding a capability.