py-pdf-parser icon indicating copy to clipboard operation
py-pdf-parser copied to clipboard

ValueError on empty ElementList.after()

Open aiden2480 opened this issue 1 month ago • 0 comments

Calling .after() on an empty ElementList throws ValueError: max() arg is an empty sequence when the method attempts to find the maximum of an empty set. A better alternative might be to throw NoElementFoundError, or return an empty ElementList

    def after(self, element: "PDFElement", inclusive: bool = False) -> "ElementList":
        """
        Returns all elements after the specified element.
    
        By after, we mean succeeding elements according to their index. The PDFDocument
        will order elements according to the specified element_ordering (which defaults
        to left to right, top to bottom).
    
        Args:
            element (PDFElement): The element in question.
            inclusive (bool, optional): Whether the include `element` in the returned
                results. Default: False.
    
        Returns:
            ElementList: The filtered list.
        """
>       new_indexes = set(range(element._index + 1, max(self.indexes) + 1))
E       ValueError: max() arg is an empty sequence

aiden2480 avatar May 15 '24 23:05 aiden2480