Skip to content

page property of Destination is mistyped #3233

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

Open
gleachkr opened this issue Apr 2, 2025 · 2 comments
Open

page property of Destination is mistyped #3233

gleachkr opened this issue Apr 2, 2025 · 2 comments
Labels
typing Type hints are faulty

Comments

@gleachkr
Copy link

gleachkr commented Apr 2, 2025

I think this one is pretty simple. The page property of a destination is current documented (and type-annotated) as returning an Optional[int]:

def page(self) -> Optional[int]:

But in fact, what it returns is generally an IndirectObject, presumably because of how /Page is initialized here:

self[NameObject("/Page")] = page
.

@stefan6419846
Copy link
Collaborator

Thanks for the report. Unfortunately, I have some doubts that this is simple to fix.

Looking at

page: Union[NumberObject, IndirectObject, NullObject, DictionaryObject],
indicates that we have quite some options for values here.
be an instance of :class:`IndirectObject<pypdf.generic.IndirectObject>`.
states that it should only hold an IndirectObject, while
@property
def page(self) -> Optional[int]:
"""Read-only property accessing the destination page number."""
return self.get("/Page")
refers to a page number we most likely never have.

You are of course invited to analyze this in detail and report here and open a corresponding PR if you have found a proper solution, but for now I honestly have some doubts that we can expect to have a consistent value here given the wide range of input data.

@stefan6419846 stefan6419846 added the typing Type hints are faulty label Apr 2, 2025
@gleachkr
Copy link
Author

gleachkr commented Apr 2, 2025

That's too bad - I'm sorry, I don't really have a proposal for how to fix this properly.

I think it would make sense to change the type hint and docstring to be consistent with Line 1624. The actual behavior of the page is to at least sometimes return an IndirectObject, so that should somehow be indicated in the documentation of the page property.

@stefan6419846 stefan6419846 changed the title page property of Destination is mistyped. page property of Destination is mistyped Apr 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
typing Type hints are faulty
Projects
None yet
Development

No branches or pull requests

2 participants