feat: Add type hinting#791
Conversation
ebb5665 to
6b258c4
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #791 +/- ##
==========================================
- Coverage 96.67% 95.53% -1.15%
==========================================
Files 27 27
Lines 3553 3871 +318
==========================================
+ Hits 3435 3698 +263
- Misses 118 173 +55 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
6b258c4 to
6c06307
Compare
6c06307 to
2a23a5a
Compare
This adds nearly full type hinting, and enables all but two of the mypy checks that were enabled in the mypy section in pyproject.toml. I hope to address the remaining checks, but it was proving tricky to address some of the 'typing.Any' uses. Also if you enable deprecation checks with --enable-error-code=deprecated You'll get warnings if you use deprecated options (at least as far as I was able to spot them!) This addresses python-zk#647 but there's not entirely strict checking as yet. Although I've tried very hard not to change any code for this, some `return None` statements have been added, which has caused the code coverage to drop as apparently those return paths were not covered by the testing. Also I've been less polite with the testing, and have changed the code in a number of places, including dropping test classes that did nothing, and adding asserts here and there to keep mypy happy as it sometimes doesn't spot a value could have been changed. I've added FIXMEs to address some of the more egregious type warning suppression that I did to avoid doing code changes, and intend to address those in another PR. A note: I've also had to suppress some errors in flake8 and use more general 'type: ignore' suppressions than I'd like because hound CI does something very very odd and tries to parse the text in the [] of the type: ignore[] comments as python, and generates some very peculiar messages.
2a23a5a to
3a14bc1
Compare
|
Hello, Thanks a lot for the PR and the issues you tagged along the way, it's really appreciated to have some fresh eyes on the project. This PR is quite big so I tagged the @python-zk/maintainers team to have feedback. As for me, I am not really a use-typing-in-Python guy. When I need typing, I use another language, but I know those changes are very valuable for the community. I will review it in the next days as I have some time off. Special pings to @a-ungurianu and @bringhurst: since you worked on typing features in the past, it would be really appreciated if you can chime in and add a review. |
This adds nearly full type hinting, and enables all but two of the checks that were enabled in the
mypysection inpyproject.toml. I hope to address the remaining checks, but it was proving tricky to address some of thetyping.Anyuses without code changes.Also if you enable deprecation checks with
--enable-error-code=deprecated, you'll get warnings if you use deprecated options (at least as far as I was able to spot them!)This addresses #647 but there's not entirely strict checking as yet.
Although I've tried very hard not to change any code for this, some
return Nonestatements have been added, which has caused the code coverage to drop as apparently those return paths were not covered by the testing.Also I've been less polite with the testing, and have changed the code in a number of places, including dropping test classes that did nothing, and adding
assertshere and there to keepmypyhappy as it sometimes doesn't spot a value could have been changed.I've added
FIXMEs to indicate some of the more egregious type warning suppression that I did to avoid doing code changes, and intend to address those in another PR.I've also added tests for the
serialization.pymodule as some of it is a little unexpected and at one point I'd managed to break it but the resultant errors were very very unclear.A note: I've also had to suppress some errors in
flake8and use more general#type: ignoresuppressions than I'd like because hound CI does something very very odd and tries to parse the text in the[]of the#type: ignore[]comments as python, and generates some very peculiar messages.Why is this needed?
Type hinting makes it much easier for users to ensure they have the right parameters for functions.
Proposed Changes
Does this PR introduce any breaking change?
Well, it might break people who're already using mypy. And it's entirely possible I've got the wrong type hints (though hopefully actually using the type hinting in the tests has pulled all those out - it certainly picked up a couple of places where I'd got it wrong).
Codecov notes:
eventlet.py- this says it's missing coverage for theeventletevent_object,lock_objectandrlock_object.SequentialEventletHandlertest_eventlet_handlerwhich doesn't have enough in it to trigger lockingtest_cache.pywhich will useSequentialEventletHanderif it can't findSequentialGeventHandler- which as far as I can see it always will.connection.py- Apparently it doesn't drop out of the main loop innext_server. However, the only way I can see it doing that is if the hosts list is empty, which I don't think is a reasonable situation. Additionally, codecov on earlier code was showing the clearly unreachable code before the end of the loop as being covered.utils.py- Caused by an explicitreturn Noneat the end of a function instead of the implicit one. Cannot tell if this path was ever covered.lock.py- Caused by an explicitreturn Noneat the end of a function instead of the implicit one. Cannot tell if this path was ever covered.