fix: sync Python type stubs (.pyi) with actual bindings and fix doc bugs (#250)
## 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.
This commit is contained in:
@@ -10,6 +10,9 @@ class PdfResult:
|
||||
page_count: int
|
||||
processing_time_ms: int
|
||||
pages_needing_ocr: list[int]
|
||||
"""1-indexed page numbers that need OCR."""
|
||||
ocr_reasons_by_page: list["PageOcrReasons"]
|
||||
"""Machine-readable OCR reasons by 1-indexed page."""
|
||||
title: Optional[str]
|
||||
confidence: float
|
||||
is_complex_layout: bool
|
||||
@@ -17,6 +20,13 @@ class PdfResult:
|
||||
pages_with_columns: list[int]
|
||||
has_encoding_issues: bool
|
||||
|
||||
class PageOcrReasons:
|
||||
"""OCR reasons for a single 1-indexed page."""
|
||||
page: int
|
||||
"""1-indexed page number."""
|
||||
reasons: list[str]
|
||||
"""Machine-readable OCR reason identifiers."""
|
||||
|
||||
class PdfClassification:
|
||||
"""Lightweight PDF classification result."""
|
||||
pdf_type: str
|
||||
@@ -47,6 +57,8 @@ class RegionText:
|
||||
text: str
|
||||
needs_ocr: bool
|
||||
"""True when the text should not be trusted."""
|
||||
ocr_reason: Optional[str]
|
||||
"""Machine-readable OCR reason when the cause is known."""
|
||||
|
||||
class PageRegionTexts:
|
||||
"""Extracted text for one page's regions."""
|
||||
@@ -62,6 +74,8 @@ class PageMarkdown:
|
||||
"""Formatted markdown for this page (empty string when needs_ocr is True)."""
|
||||
needs_ocr: bool
|
||||
"""True when text on this page is unreliable and OCR should be used instead."""
|
||||
ocr_reason: Optional[str]
|
||||
"""Machine-readable OCR reason when the cause is known."""
|
||||
|
||||
class PagesExtractionResult:
|
||||
"""Per-page markdown output with document-wide layout classification."""
|
||||
@@ -73,6 +87,8 @@ class PagesExtractionResult:
|
||||
"""1-indexed pages where multi-column layout was detected."""
|
||||
pages_needing_ocr: list[int]
|
||||
"""1-indexed pages that need OCR."""
|
||||
ocr_reasons_by_page: list[PageOcrReasons]
|
||||
"""Machine-readable OCR reasons by 1-indexed page."""
|
||||
is_complex: bool
|
||||
"""True if any page has tables or multi-column layout."""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user