Skip to content

Commit 7ed78c6

Browse files
committed
fix: sync Python type stubs (.pyi) with actual bindings and fix doc bugs
## Bug 1: Python type stubs missing 5 fields/classes The pdf_inspector.pyi file was out of sync with the actual Python bindings exposed via #[pyo3(get)] in src/python.rs. This breaks IDE autocompletion and type checking (PyCharm, VS Code/Pylance, mypy) for all Python users. Added: - PdfResult.ocr_reasons_by_page (python.rs:35) - PageOcrReasons class with page and easons fields (python.rs:67-86) - RegionText.ocr_reason (python.rs:136) - PageMarkdown.ocr_reason (python.rs:193) - PagesExtractionResult.ocr_reasons_by_page (python.rs:226) ## Bug 2: PdfResult.pages_needing_ocr indexing undocumented PdfResult.pages_needing_ocr is 1-indexed (per python.rs:30) but neither the .pyi stubs nor docs/python.md annotated this, while the same field on PdfClassification was annotated as 0-indexed. Users mixing both APIs would get wrong page numbers. ## Bug 3: README.md duplicate bullet character The Markdown features table listed * twice in bullet prefixes. The first should be �ullet (U+2022), matching the actual source code in src/markdown/mod.rs:34 which uses: �ullet, dash, �sterisk, circle, illed-circle, open-circle. ## Bug 4: docs/python.md missing fields in type reference The Types section was missing PageOcrReasons, RegionText class definition, ocr_reason fields, and ocr_reasons_by_page fields. ## Evidence Cross-referenced every #[pyo3(get)] attribute in src/python.rs against the .pyi declarations and docs/python.md type reference.
1 parent ae6246b commit 7ed78c6

3 files changed

Lines changed: 31 additions & 4 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ The converter handles:
238238
|---|---|
239239
| Headings (H1-H4) | Font size tiers relative to body text, with 0.5pt clustering |
240240
| Bold/italic | Font name patterns (Bold, Italic, Oblique) |
241-
| Bullet lists | `*`, `-`, `*`, ``, ``, `` prefixes |
241+
| Bullet lists | ``, `-`, `*`, ``, ``, `` prefixes |
242242
| Numbered lists | `1.`, `1)`, `(1)` patterns |
243243
| Letter lists | `a.`, `a)`, `(a)` patterns |
244244
| Code blocks | Monospace fonts (Courier, Consolas, Monaco, Menlo, Fira Code, JetBrains Mono) and keyword detection |

docs/python.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,19 @@ class PdfResult: # process_pdf / detect_pdf
111111
markdown: str | None # extracted Markdown (None for detect_pdf)
112112
page_count: int
113113
processing_time_ms: int
114-
pages_needing_ocr: list[int]
114+
pages_needing_ocr: list[int] # 1-indexed
115+
ocr_reasons_by_page: list[PageOcrReasons]
115116
title: str | None
116117
confidence: float # 0.0 - 1.0
117118
is_complex_layout: bool
118119
pages_with_tables: list[int]
119120
pages_with_columns: list[int]
120121
has_encoding_issues: bool # broken font encodings — consider OCR fallback
121122

123+
class PageOcrReasons: # per-page OCR diagnostics
124+
page: int # 1-indexed
125+
reasons: list[str] # machine-readable reason identifiers
126+
122127
class PdfClassification: # classify_pdf
123128
pdf_type: str
124129
page_count: int
@@ -140,14 +145,20 @@ class TextItem: # extract_text_with_positions
140145
is_strikeout: bool
141146
item_type: str
142147

148+
class RegionText: # extract_text_in_regions
149+
text: str
150+
needs_ocr: bool
151+
ocr_reason: str | None # machine-readable OCR reason
152+
143153
class PageRegionTexts: # extract_text_in_regions
144154
page: int # 0-indexed
145-
regions: list[RegionText] # RegionText: text: str, needs_ocr: bool
155+
regions: list[RegionText]
146156

147157
class PagesExtractionResult: # extract_pages_markdown
148-
pages: list[PageMarkdown] # PageMarkdown: page (0-indexed), markdown, needs_ocr
158+
pages: list[PageMarkdown] # PageMarkdown: page (0-indexed), markdown, needs_ocr, ocr_reason
149159
pages_with_tables: list[int] # 1-indexed
150160
pages_with_columns: list[int] # 1-indexed
151161
pages_needing_ocr: list[int] # 1-indexed
162+
ocr_reasons_by_page: list[PageOcrReasons]
152163
is_complex: bool # any page has tables or multi-column layout
153164
```

pdf_inspector.pyi

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,23 @@ class PdfResult:
1010
page_count: int
1111
processing_time_ms: int
1212
pages_needing_ocr: list[int]
13+
"""1-indexed page numbers that need OCR."""
14+
ocr_reasons_by_page: list["PageOcrReasons"]
15+
"""Machine-readable OCR reasons by 1-indexed page."""
1316
title: Optional[str]
1417
confidence: float
1518
is_complex_layout: bool
1619
pages_with_tables: list[int]
1720
pages_with_columns: list[int]
1821
has_encoding_issues: bool
1922

23+
class PageOcrReasons:
24+
"""OCR reasons for a single 1-indexed page."""
25+
page: int
26+
"""1-indexed page number."""
27+
reasons: list[str]
28+
"""Machine-readable OCR reason identifiers."""
29+
2030
class PdfClassification:
2131
"""Lightweight PDF classification result."""
2232
pdf_type: str
@@ -47,6 +57,8 @@ class RegionText:
4757
text: str
4858
needs_ocr: bool
4959
"""True when the text should not be trusted."""
60+
ocr_reason: Optional[str]
61+
"""Machine-readable OCR reason when the cause is known."""
5062

5163
class PageRegionTexts:
5264
"""Extracted text for one page's regions."""
@@ -62,6 +74,8 @@ class PageMarkdown:
6274
"""Formatted markdown for this page (empty string when needs_ocr is True)."""
6375
needs_ocr: bool
6476
"""True when text on this page is unreliable and OCR should be used instead."""
77+
ocr_reason: Optional[str]
78+
"""Machine-readable OCR reason when the cause is known."""
6579

6680
class PagesExtractionResult:
6781
"""Per-page markdown output with document-wide layout classification."""
@@ -73,6 +87,8 @@ class PagesExtractionResult:
7387
"""1-indexed pages where multi-column layout was detected."""
7488
pages_needing_ocr: list[int]
7589
"""1-indexed pages that need OCR."""
90+
ocr_reasons_by_page: list[PageOcrReasons]
91+
"""Machine-readable OCR reasons by 1-indexed page."""
7692
is_complex: bool
7793
"""True if any page has tables or multi-column layout."""
7894

0 commit comments

Comments
 (0)