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

Provide type hint information for users #126

Closed
wants to merge 7 commits into from

Conversation

eggplants
Copy link

@eggplants eggplants commented Oct 11, 2023

Description

I have introduced mypy and fixed some errors. And then I have added py.typed file to package_data to mark this package is typed. (See PEP561)

Breaking changes

List any changes that break the API usage supported on master.

The annotation of Search.max_results changes from float into int. If the instance variable is float like 10.0, the Arxiv API raises max_results must be an integer.
https://export.arxiv.org/api/query?search_query=all:electron&max_results=10.0

import arxiv

client = arxiv.Client(page_size=10, delay_seconds=0)
search = arxiv.Search(query="testing", max_results=2.0)
client.results(search)
# arxiv.arxiv.HTTPError: Page request resulted in HTTP 400: max_results must be an integer (http://export.arxiv.org/api/query?search_query=testing&id_list=&sortBy=relevance&sortOrder=descending&start=0&max_results=2.0)

Relevant issues

Not found.

Checklist

...

Comment on lines +6 to +7
# FIXME: feedparser includes py.typed file after 7.x.
import feedparser # type: ignore[import-untyped]
Copy link
Author

Choose a reason for hiding this comment

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

Comment on lines -440 to +445
max_results: float = float("inf"),
max_results: int = cast(int, float("inf")),
Copy link
Author

Choose a reason for hiding this comment

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

float("inf") treats as int in type level.

Comment on lines +212 to +213
# FIXME: `self.pdf_url` is possibly `None` and following code raises `TypeError`.
written_path, _ = urlretrieve(self.pdf_url, path) # type: ignore[arg-type]
Copy link
Author

Choose a reason for hiding this comment

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

arxiv.Result._get_pdf_url([]) returns None and it raises TypeError in this line.

Comment on lines +227 to +228
# FIXME: `self.pdf_url` is possibly `None` and following code raises `AttributeError`.
source_url = self.pdf_url.replace("/pdf/", "/src/") # type: ignore[union-attr]
Copy link
Author

Choose a reason for hiding this comment

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

arxiv.Result._get_pdf_url([]) returns None and it raises AttributeError in this line.

@lukasschwab
Copy link
Owner

@eggplants thanks for submitting this. I'm running a bit behind on reviews — this interacts with #124, which is also in my review queue. Thanks for your patience 🙇

@eggplants eggplants closed this Nov 11, 2023
@eggplants eggplants deleted the typed branch November 11, 2023 07:10
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.

2 participants