feat: Add type hinting#791
Open
ThosRTanner wants to merge 1 commit into
Open
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
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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).