gkeepapi icon indicating copy to clipboard operation
gkeepapi copied to clipboard

Add type hints

Open PrOF-kk opened this issue 4 years ago • 9 comments

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

PrOF-kk avatar Feb 05 '22 12:02 PrOF-kk

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. :]

kiwiz avatar Feb 05 '22 18:02 kiwiz

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?

PrOF-kk avatar Feb 07 '22 21:02 PrOF-kk

Let's use the latter to maximize compat.

kiwiz avatar Feb 08 '22 01:02 kiwiz

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

PrOF-kk avatar Feb 08 '22 12:02 PrOF-kk

Done. :+1:

kiwiz avatar Feb 08 '22 14:02 kiwiz

Missed 2 raise_from @ L1820 and L1929

PrOF-kk avatar Feb 08 '22 19:02 PrOF-kk

Thanks, pushed up fixes.

kiwiz avatar Feb 09 '22 03:02 kiwiz

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.

PrOF-kk avatar Feb 26 '22 23:02 PrOF-kk

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 avatar Feb 26 '22 23:02 kiwiz

Tracking in #130

kiwiz avatar Sep 21 '23 04:09 kiwiz