anitopy icon indicating copy to clipboard operation
anitopy copied to clipboard

Feat: add type-hinting for the public API

Open tylergibbs2 opened this issue 2 years ago • 4 comments

This PR adds a stub file anitopy.pyi to add backwards compatible type-hinting to the public anitopy.parse API.

@igorcmoura if you are interested in also type-hinting the internal methods, please do not merge this just yet. If you are interested, I'll add that into this PR as well.

https://user-images.githubusercontent.com/1884865/205460778-84134935-d86c-4777-82cb-488893b539d5.mp4

tylergibbs2 avatar Dec 03 '22 20:12 tylergibbs2

Oh my god! That's very useful actually

If you could add type-hinting to the internal methods, I would appreciate it very much!

igorcmoura avatar Dec 03 '22 21:12 igorcmoura

@igorcmoura Ready for review!

I learned of a slight problem with stub files, though. Apparently the types cannot be used within the same file. For example, the types in token.pyi aren't recognized in token.py. They do work when they are imported in other files, though.

The py.typed file is required to bundle the stub files on PyPI release. See here for more info.

I also modified the flake8 configuration to perform linting on the new stub files.

tylergibbs2 avatar Dec 05 '22 01:12 tylergibbs2

Sorry for taking so long to reply, it's been a long time since the last time I logged in GitHub.

I'll check this PR as soon as I can, but I'll have to learn a bit about these .pyi since it's the first time I've seen it. What's the difference between using them and typing directly into the .py files?

igorcmoura avatar Mar 15 '23 22:03 igorcmoura

No worries about the delay, thanks for taking the time to look.

The problem with having the types directly in the file (in this case) is that the syntax is not supported in Python 2, which I believe anitopy still supports. If you wanted to drop support for Python 2, then the types could be included directly within the source code instead of having the .pyi files.

tylergibbs2 avatar Mar 15 '23 22:03 tylergibbs2