Skip to content

Switch to None or Exception for page_number / get_page_number / get_destination_page_number #1914

@MartinThoma

Description

@MartinThoma

Explanation

If a page is not attached to a document, it does not have a page number. So we cannot return a "normal" number.
At the moment, we return -1.

However, callers (users of the library) might not be careful with error handling.

For this reason I suggest to change the behavior to either return None or raise an Exception. I'm not sure what is better.

Pro returning None:

  • It makes intuitive sense what it means
  • It is part of the type annotation and mypy will complain about it if you don't handle that
  • Callers just need to check for None and don't need to catch an exception - which I personally prefer.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions