Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueError on empty ElementList.after() #386

Open
aiden2480 opened this issue May 15, 2024 · 2 comments
Open

ValueError on empty ElementList.after() #386

aiden2480 opened this issue May 15, 2024 · 2 comments

Comments

@aiden2480
Copy link
Contributor

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 aiden2480 added the bug label May 15, 2024
@jstockwin
Copy link
Owner

Agreed this is a good fix. Given the return type is an ElementList I'd be in favour of returning an empty ElementList here.

Happy to review a PR 👍

@aiden2480
Copy link
Contributor Author

I'm happy to make a PR. I'll include before as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants