-
Notifications
You must be signed in to change notification settings - Fork 12
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
Add static type checking with MyPy #143
Conversation
On it! |
I'm assuming you've already taken care of the 1st three bullets? |
Yes, the bullets that I checked are already done in this PR |
Some changes that satisfy Mypy result in errors in pytest. Is that expected? |
Not sure what you mean - let me know if you see this being reproduced in the CI tests. For the most part, changing type annotations doesn't change executed code (except in the case of forward references... you can google that if you do end up with an issue like this) |
So I fix it by changing fixes Mypy but when I run pytest, this fails.
|
The fix seems to be |
Yes that's the fix! Welcome to the wild world of dataclasses. But when you add one of these factories, you should also ask yourself if a developer should ever actually be able to create an instance of this class without an predefined prefix map. There are a lot of instances where it seemed to me that this hadn't been considered |
@hrshdhgd thanks for being patient - I merged the other PR then updated into this one, so we can continue here |
Hey both, this PR lets my heart race in happiness - please let me know if you need me to take over and finish it - we should merge asap and make a new release, and hopefully than this was the last of the massive refactor PRs for a while :) thank you both. Just one thing: lets please strictly adhere to mypy here and not address any other issues. If you find other stuff, make issue for them. |
There are all sorts of problems this pointed out, but I only did minimal code changing to address some of them. There are now some failing tests since the assumptions of those functions were completely broken before (regarding default prefix map loading)
@matentzn @hrshdhgd I've finished updating all of the type checking (only in a few places using ignores, such as the crazy typing in the autogenerated code). There were a lot of places where the handling of falsy prefix maps (e.g., None or empty) were not explicit. This made it really hard to figure out what the business logic should be. Because I've done what it took to make the program make sense, there are now a few failing tests, so I'd suggest Nico goes through the deep set of functions handling these prefix maps and figures out which business logic should be the right one. I know it was your goal to do minimum code changes, but type checking exposes logical errors that fully call for refactoring and bug fixing, so we're just lucky it wasn't more |
@hrshdhgd better to fail fast and raise exceptions rather than flutter around in deeply nested logic
Tests Pass!! |
Everyone can take a look tomorrow to see if any of the changes we made weren't covered by tests. Otherwise, let's get this merged and move on with more fun refactoring in a future PR! |
Special thanks to @hrshdhgd who got up to speed on this type checking stuff super fast!! |
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.
This is a huge applause to both of you. I am impressed - some of the python is a good deal beyond my current ability and just reading this PR has thought me a great deal.
If we could make sure that make test
also runs the mypy, that'd be great.
Thank you so much @cthoyt - If one of you could resolve all the open conversations I think this can be merged! |
Blocked by #146
This PR does the following:
mypy
environment totox.ini
pyproject.toml
to exclude auto-generated modulesmypy
testing to CI configuration