py-pdf-parser
py-pdf-parser copied to clipboard
ValueError on empty ElementList.after()
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