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

Add type hints #118

Closed
PrOF-kk opened this issue Feb 5, 2022 · 10 comments
Closed

Add type hints #118

PrOF-kk opened this issue Feb 5, 2022 · 10 comments

Comments

@PrOF-kk
Copy link
Contributor

PrOF-kk commented Feb 5, 2022

Consider adding type hints so type checkers like mypy and on-the-fly documentation can work properly, at least for the most commonly used methods.
The return types are often already included in the documentation but aren't recognised correctly:
Imgur
I'd expect something like (method) get: (note_id) -> gkeepapi.node.TopLevelNode | None instead

@kiwiz
Copy link
Owner

kiwiz commented Feb 5, 2022

This was primarily to maintain Py2 compatibility, but we should now be in the clear. All deprecation work is currently tracked in the https://github.com/kiwiz/gkeepapi/tree/deprecate_py2 branch. If you're feeling adventurous, PRs are welcome. :]

@PrOF-kk
Copy link
Contributor Author

PrOF-kk commented Feb 7, 2022

Sure, I'll take a look at adding them.
Can we use 3.10-style union types TopLevelNode | Node or should we support ≤ 3.9 with Union[TopLevelNode, None] instead?

@kiwiz
Copy link
Owner

kiwiz commented Feb 8, 2022

Let's use the latter to maximize compat.

@PrOF-kk
Copy link
Contributor Author

PrOF-kk commented Feb 8, 2022

Sure, I'll do it. Could you please rebase the branch?

@kiwiz
Copy link
Owner

kiwiz commented Feb 8, 2022

Done. 👍

@PrOF-kk
Copy link
Contributor Author

PrOF-kk commented Feb 8, 2022

Missed 2 raise_from @ L1820 and L1929

@kiwiz
Copy link
Owner

kiwiz commented Feb 9, 2022

Thanks, pushed up fixes.

@PrOF-kk
Copy link
Contributor Author

PrOF-kk commented Feb 26, 2022

Alright so instead of adding typing for everything all at once I'll focus on adding the initial Keep class typing, since that's the user-facing part. Some notes:

In Keep::login we get an APIAuth object to login and then branch on its return value, but APIAuth::login always returns True if it doesn't raise a LoginException. We then return True for Keep::login as well. Is this intentional?

Since Python doesn't have method overloading this update overrides this update.

@kiwiz
Copy link
Owner

kiwiz commented Feb 26, 2022

Keep::login

Hmm, these probably shouldn't return anything. In the interest of preserving backwards compat, let's not document the return value, but keep them for now. The if statements can probably be removed.

RemindersAPI

Good eye. The reminders functionality doesn't work atm, but I would rename the second update to sync.

@kiwiz
Copy link
Owner

kiwiz commented Sep 21, 2023

Tracking in #130

@kiwiz kiwiz closed this as completed Sep 21, 2023
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

No branches or pull requests

2 participants