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

adding some type hints and few type checks #55

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

farooqkz
Copy link

Hello there.
I have added some Python type hints and a few type checks.
Please let me know if I should change anything.
Regards, Farooq.

Copy link
Owner

@cbrunet cbrunet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution.

I wasn't sure about type annotations, but I think we can add them. Just be sure to stay compatible with Python 3.5. And we should annotate all python files not just document and image.

src/poppler/document.py Outdated Show resolved Hide resolved
)


def load_from_data(file_data: bytes, owner_password=None, user_password=None):
def load_from_data(
file_data: bytes, owner_password: str = "", user_password: str = ""
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer using None for default It is more explicit. With you suggestion, it is no longer possible to use None as argument to the function.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apart from that, usually using None means no password, while "" could be an empty one. Don't know, how poppler/pdf deals with empty passwords...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know much about PDFs but if empty password is a valid password for a PDF then I agree with you being None for default. otherwise it is better to use empty string as default.
Waiting for your comment @cbrunet

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The C++ API expects an empty string. However, semantically, in Python, None means no value. Since we are in the context of a library, I prefer to let the user choose the value that is more suitable for him. Furthermore, annotating the password field as Optional[str] is more expressive, imho.

@farooqkz
Copy link
Author

So you are asking me to add type hints to all files?

src/poppler/document.py Outdated Show resolved Hide resolved
src/poppler/document.py Outdated Show resolved Hide resolved
src/poppler/document.py Outdated Show resolved Hide resolved
)


def load_from_data(file_data: bytes, owner_password=None, user_password=None):
def load_from_data(
file_data: bytes, owner_password: str = "", user_password: str = ""
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The C++ API expects an empty string. However, semantically, in Python, None means no value. Since we are in the context of a library, I prefer to let the user choose the value that is more suitable for him. Furthermore, annotating the password field as Optional[str] is more expressive, imho.

@cbrunet
Copy link
Owner

cbrunet commented Apr 21, 2022

So you are asking me to add type hints to all files?

yes, if it is something you'd like to do, it would be a great contribution. I would not add any explicit type checks however.

@farooqkz
Copy link
Author

So you are asking me to add type hints to all files?

yes, if it is something you'd like to do, it would be a great contribution. I would not add any explicit type checks however.

Currently, I don't have time to do the type hints for all of the API. And I suppose having type hints for some parts is better than not having them at all.

@farooqkz
Copy link
Author

farooqkz commented Dec 3, 2022

@cbrunet any other change required?

EDIT: Sorry I forgot it for a long time...

@farooqkz
Copy link
Author

@cbrunet enough sleep! wake up!

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

Successfully merging this pull request may close these issues.

3 participants