Skip to content

Conversation

@tylergibbs2
Copy link
Contributor

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.

Code_l4xJsL5EbE.mp4

@igorcmoura
Copy link
Owner

Oh my god! That's very useful actually

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

@tylergibbs2
Copy link
Contributor Author

@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.

@igorcmoura
Copy link
Owner

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?

@tylergibbs2
Copy link
Contributor Author

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.

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