Add type hints to the code base, add type checking in CI
Is your feature request related to a problem? Please describe.
The alot code base is quite big and we already specify many types in the docstrings. They are rendered in the docs and might get picked up by IDEs but are not automatically verified in CI.
The python ecosystem supports optional static typing which can be used by type checkers (CI), IDEs and even sphinx.
Describe the solution you'd like
- Introduce type hints in the code base (gradually)
- Check them in CI (with mypy or similar tools)
Describe alternatives you've considered
Don't do it.
Additional context
As many editors support LSP nowadays I hope that this helps (new) contributors finding their way around the code base. (It would certainly help me in that respect)
This issue is mainly to ask @pazz if you are ok with this plan :)
@lucc yes of course!
As mentioned before, I am grateful to you for keeping this project alive and am have long since "stepped down" into the role of a happy user who may be able to explain some of the code quirks when necessary. I support any kind of modernisation, whatever keeps users engaged and helps newcomers.
I think this is a decent start although I think some added type hints like function types returning Any look somewhat intimidating for newcomers to the code.
feel free to review and trigger more copilot revisions in #1695 directly. If you're happy with it I suggest you ask for hints for the whole codebase and to remove hints from sphinx docs if that's unnecessary then. Thanks
@pazz I tried to have copilot rebase the code in #1695 but it did not react so I did that myself. The official docs said "interact with copilot how you would with any human contributor".
What do you think, should we merge #1695 or ask it to take my changes as an example and annotate more code?
I don't really have a strong preference here. To me, the whole business with type hints looks like patching up the issue that python isn't really meant for safe code and I'm not convinced that the added security makes up for the slightly less readable and welcoming code. But I am happy to go along with this if you think type hints are good to have.
One general thing to note is that copilot often makes a good start and then does not consequently follow up. As is here, it stopped adding hints after about half of the codebase. You'd have to re-trigger it with specific instructions for those parts you notice that hints are still missing. I found that copilot in VSCode is a little easier to "reign in" in the sense that you fully control what is committed (as opposed to assigning issues on github, which leaves the commit history a bit messy).
Long story short, I'm happy to merge this. It looks safe and if you like it go for it :)
@pazz wrote:
As is here, it stopped adding hints after about half of the codebase.
I can only see that copilot added type hints for three files, far from half of the alot code base. Where is the rest of these changes?
this was meant as loose upper bound, there is not more. 🙂