|
2 | 2 | import logging.config
|
3 | 3 | from datetime import date
|
4 | 4 | from enum import Enum
|
5 |
| -from typing import Optional, Sequence, Tuple, List, Union, Mapping, Any |
| 5 | +from typing import Any, List, Mapping, Optional, Sequence, Tuple, TypeVar, Union |
6 | 6 | from collections import Counter
|
7 | 7 |
|
8 | 8 | from deprecation import deprecated
|
@@ -164,6 +164,9 @@ class PDFData(BaseModel):
|
164 | 164 | text_blocks: Sequence[PDFTextBlock]
|
165 | 165 |
|
166 | 166 |
|
| 167 | +_PO = TypeVar("_PO", bound="BaseParserOutput") |
| 168 | + |
| 169 | + |
167 | 170 | class BaseParserOutput(BaseModel):
|
168 | 171 | """Base class for an output to a parser."""
|
169 | 172 |
|
@@ -247,7 +250,7 @@ def to_string(self) -> str: # type: ignore
|
247 | 250 | [text_block.to_string().strip() for text_block in self.text_blocks]
|
248 | 251 | )
|
249 | 252 |
|
250 |
| - def detect_and_set_languages(self) -> "BaseParserOutput": |
| 253 | + def detect_and_set_languages(self: _PO) -> _PO: |
251 | 254 | """
|
252 | 255 | Detect language of the text and set the language attribute.
|
253 | 256 |
|
@@ -281,8 +284,8 @@ def detect_and_set_languages(self) -> "BaseParserOutput":
|
281 | 284 | return self
|
282 | 285 |
|
283 | 286 | def set_document_languages_from_text_blocks(
|
284 |
| - self, min_language_proportion: float = 0.4 |
285 |
| - ): |
| 287 | + self: _PO, min_language_proportion: float = 0.4 |
| 288 | + ) -> _PO: |
286 | 289 | """
|
287 | 290 | Store the document languages attribute as part of the object.
|
288 | 291 |
|
@@ -311,7 +314,7 @@ def set_document_languages_from_text_blocks(
|
311 | 314 |
|
312 | 315 | return self
|
313 | 316 |
|
314 |
| - def vertically_flip_text_block_coords(self) -> "BaseParserOutput": |
| 317 | + def vertically_flip_text_block_coords(self: _PO) -> _PO: |
315 | 318 | """
|
316 | 319 | Flips the coordinates of all PDF text blocks vertically.
|
317 | 320 |
|
|
0 commit comments