-
-
Notifications
You must be signed in to change notification settings - Fork 409
sopel: type hint and basic setup #2185
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Fixed a conflict. Still no review, do you hate type hinting? 😄 |
dgw
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still no review, do you hate type hinting? 😄
Other things keep distracting me. Refactoring code to do the same thing isn't sexy. 😛
It's safe to say I have some questions, and some opinions. Surely you expected that and it's why you wanted a review. So here you go: a start to the process. I can't promise when I'll be able to look at this again, but then neither can you, so it works out. 😎
|
Instead of replying to all your comments, I should have read them all, then write this long reply in one go. Sorry for the noises! There are numerous comments that require a deeper explanation. The first thing to know: I wrote that 3 months ago, and I don't remember everything. Also, some things have changed since then (Sphinx got a new release in November, and I just saw that mypy got a release yesterday). Mypy and type-hint is moving fast in the Python community. As an example of that, the first time I tried to type-hint Sopel and use mypy (earlier this year, before September), SQLAlchemy didn't provide a stub library (or it wasn't working properly). In any case, I'm not 100% confident in my own work. What I'm sure about, however, is my goals:
Now, to the details. Weak type-hint and the usage of
|
dgw
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dropped specific responses into the relevant open conversations, and marked some others as resolved because they were answered by another reply.
Out of everything you said in the big omni-reply comment, there's nothing for me to really disagree on. You're absolutely right that we shouldn't enforce any of this in make qa yet, and that there are several logical next steps from here. Not enforcing the checks means we can indeed take it one thing at a time and add annotations gradually.
Assuming GitHub behaves despite my present abuse of the "review" mechanism to collect my replies and send them all at once, only stuff I still want to see changed or talk about more is still open. I'll go through the conversation list again after I submit to make sure resolved stuff stayed resolved.
dgw
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a small merge conflict with #2179 now, but if you don't have any squashing/reordering to do I'm happy to just merge on the CLI and handle it, to save you the time.
In order to use mypy, we need: * to install mypy (dev) * to install type stubs (dev) * to upgrade pytest (dev) * to upgrade sqlalchemy (requirements) * to have `make mypy` available This commit doesn't make Sopel fully compatible, as built-in plugins need some adaptation and/or "type: ignore" flags.
Python will implicitely define this method as None: A class that overrides __eq__() and does not define __hash__() will have its __hash__() implicitly set to None. There is no need to keep this line.
Fixed. Nothing squashed, I kept everything as it is. |
Description
I wanted to add type annotation, and make sure they actually work, i.e. that mypy could validate them. So I installed it, ran it, and... got a load of errors. So tried to fix them, one by one.
Some are easy to fix: for sqlalchemy or pytest, all I had to do was to upgrade the dependency. Given that we are now Py3.6+ only, it was fairly easy and shouldn't be a problem. At least I hope it won't. At least, the test suite is still running fine on my end (Py3.8), and I'm doing this PR to check how it behave on the CI too. If it doesn't work, I'll see what I can do!
Some are trivial to fix: install a type library:
Some errors are more complicated, and some are limitation of what is available in Py3.6 (compared to what you can do with 3.8 and 3.9). I don't want to use a backport library yet, because I want to make sure that the very basic typing work properly, one step at a time.
That's also why I didn't put mypy with the
make qacommand: I really like mypy, but I'd like to wait a bit before we enforce it for everyone. Making sure Sopel works is more important to me than having proper type annotations.So yeah, it's a first step, and this PR is mostly to put the tools in place and see if we can move forward with it. I hope none of the new dependency will be a problem.
Checklist
make qa(runsmake qualityandmake test)