kiwiz / gkeepapi

An unofficial client for the Google Keep API.
MIT License
1.52k stars 112 forks source link

Add initial type hints #128

Closed PrOF-kk closed 1 year ago

PrOF-kk commented 2 years ago

Closes #118

This doesn't address the update method shadowing on line 621, or the unused resync arguments

kiwiz commented 2 years ago

Thanks for adding hints and cleaning up all the docstrings.

Let me know if/once you're done with this PR and I can merge and do any cleanup.

PrOF-kk commented 1 year ago

Sorry for the delay, I must've missed the notification.

  • Are bools implicitly typed in some way?

The (IDE/linter/type checker) should be able to already correctly guess the type for that: VSCode example
I didn't add : bool because the method signature is already pretty messy and didn't want to make it worse


  • IIRC, we can just reference re.Pattern now that we don't care about Python 2 (if you're specifically referring to the docstrings

Basically I don't understand what we're doing here, is it for Python 2 compat? https://github.com/kiwiz/gkeepapi/blob/fc21aad6f33b26f4f8c78117d2fca71f675763b6/gkeepapi/__init__.py#L23-L26 Which leads to not being sure what type to annotate query here and here: https://github.com/kiwiz/gkeepapi/blob/fc21aad6f33b26f4f8c78117d2fca71f675763b6/gkeepapi/__init__.py#L933 https://github.com/kiwiz/gkeepapi/blob/fc21aad6f33b26f4f8c78117d2fca71f675763b6/gkeepapi/__init__.py#L811-L820 I think it should be Union[re.Pattern, str] but I'm not sure

kiwiz commented 1 year ago

Got it. That sounds fine then. For re, that block of code is indeed for Py2 support - Union[re.Pattern, str] should do the trick with its removal.

PrOF-kk commented 1 year ago

I just realized typing.Optional exists, so I'll be replacing every Union[X, None] -> Optional[X]

In some places the args are optional but it's not mentioned in the docstrings, so I'll fix that too:
https://github.com/kiwiz/gkeepapi/blob/f0d066f8eda3492e9c884510265c3a2588123242/gkeepapi/__init__.py#L866-L871

Question: is there a standardized docstring format we're using here? If not (in the docstrings only, not in the typing hints), since they're comments, we could replace Unions with with X | Y and Optionals with X | None

kiwiz commented 1 year ago

Yup, the repo uses Google-style docstrings (https://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html). From a quick look at that page, it seems that Sphinx supports/knows about native type hints now. As such, I think we could just remove the typing info from the comments.

If you want to investigate, the docs can be built via the Makefile in docs/

PrOF-kk commented 1 year ago
PrOF-kk commented 1 year ago

Fixed all my mistakes, Sphinx builds the docs successfully. There's a lot of warnings but none of them are about typing, almost all are WARNING: duplicate object description of X...

Should be ready for review

kiwiz commented 1 year ago

Thanks for your work! I've merged the changes into deprecate_py2. I'll do a review of the library and then merge into main.