-
Notifications
You must be signed in to change notification settings - Fork 314
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
feat: Add mypy to CI #563
feat: Add mypy to CI #563
Conversation
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.
Good to see such a small patch :)
Mypy needs to be added to the CI (.github/workflows/check.yml
), otherwise it won’t run.
I'm converting this to a Draft, becouse mypy does not recognize fields and treats them as Any. And that's the reason it was passing in my local run. I need to ivestigate this. |
I figured it out. By default If run with Well, i think we can start with this small working merge, and see if defining proper types helps to lower error count :) |
Regarding the failure on CI, I believe we can’t |
Thanks for the last improvements. :) I added a few commits, and would be happy to get your opinion on the following changes:
|
The next step would probably be to add |
I don't see For the start it's fine to leave And i think it's better to type-check tests, because that's how library is used, and we will see what errors users will have when using it. With
For example, this looks like false positive, but it isn't. Type checker recognizes phone as str, because we haven't added types to If you want to enable it and leave tests without type-checking, it's fine. After i add types for PhoneNumberField, we can enable type checking for tests. Using pyproject.toml and unpinning dependencies is fine. |
Thanks for the input! I mistakenly took I understand your point about running type verification on the tests as well, as a verifier of types. I restored the check, with I tried typing some tests yesterday, and tripped on the following test. django-phonenumber-field/tests/test_phonenumber.py Lines 45 to 56 in 67fae02
I figured I would need to type the assertions (or use |
I think There's issue in mypy: And you can use With pyright for this case we could use tuple instead of list, and it would infer types for all elements like here: But it's better to leave |
Awesome, thanks for this investigation 😀 |
I’ll let this PR sit for a couple days, in case others want to look at it. |
Enable a baseline type checking over the project source code. Type hints improvements will follow suite. A few existing type errors were fixed in order to get the CI rolling. Using django-stubs[compatible-mypy] instead of mypy directly to ensure version compatibility between mypy and django-stubs.
7552dde
to
e02ffb5
Compare
Refs #562