From 36f2f51a06366e3ae8dea434af1653688d5b18eb Mon Sep 17 00:00:00 2001 From: Julien Raffy Date: Tue, 9 Sep 2025 08:55:37 +0200 Subject: [PATCH] feat: Add overloads to `page` method in Document class for improved type hinting --- textractor/entities/document.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/textractor/entities/document.py b/textractor/entities/document.py index fc004ef..a3a79a3 100644 --- a/textractor/entities/document.py +++ b/textractor/entities/document.py @@ -9,7 +9,7 @@ import xlsxwriter import io from pathlib import Path -from typing import List, IO, Union, AnyStr, Tuple, Optional +from typing import List, IO, Union, AnyStr, Tuple, Optional, overload from copy import deepcopy from collections import defaultdict from PIL import Image @@ -269,7 +269,13 @@ def get_text_and_words( flattened_words.extend(words) return config.layout_element_separator.join(text), flattened_words - def page(self, page_no: int = 0): + @overload + def page(self, page_no: int = 0) -> Page: ... + + @overload + def page(self, page_no: list[int]) -> list[Page]: ... + + def page(self, page_no: int | list[int] = 0) -> Page | list[Page]: """ Returns :class:`Page` object/s depending on the input page_no. Follows zero-indexing.