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 type checking (mypy) #1244
Add type checking (mypy) #1244
Conversation
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## master #1244 +/- ##
==========================================
- Coverage 68.96% 68.96% -0.01%
==========================================
Files 64 64
Lines 6944 6946 +2
Branches 1693 1696 +3
==========================================
+ Hits 4789 4790 +1
Misses 1851 1851
- Partials 304 305 +1
☔ View full report in Codecov by Sentry. |
0e7a2b3
to
04e7027
Compare
@corneliusroemer you read my mind! I was going to include pyright here but I think it's better to split that out into a separate PR. |
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.
Exciting to see type checks getting added to Augur! I left some minor comments.
bf4ff71
to
8c19b75
Compare
The codebase has sprinkles of typing here and there. Previously, they were not checked in any way and purely for extra context to readers of the code. Now, they are checked and enforced through mypy. There are several mypy errors when run against the code as-is. The following commits will address those errors. Setup was largely copied from existing mypy usage in Nextstrain CLI, including the way mypy is run via pytest.
For each external package that was missing types, add a separate type packages if available. Otherwise, ignore the absence of types.
The violations are surrounded by existing context that justify exceptions.
Minor non-functional changes to appease the type-checker. To me, the changes also better describe the code's purpose.
This shows the effects of an existing bug, to be fixed in the following commit.
8c19b75
to
2a74460
Compare
Previously, if --fix-dates was not specified, it would behave as if --fix-dates='monthfirst' were used. This change was inadvertently left out of e82d314. Previous code ran without errors because `fix_dates` is the name of a function. The bug was noticed by a Mypy warning hinting that `fix_dates` will always be truthy.
The type of the delimiter parameter to csv.Sniffer.sniff is str, so that's what should be accepted here. Also check to ensure that delimiters are single characters.
ebf4c97
to
a5c173a
Compare
@@ -290,7 +290,7 @@ def available_cpu_cores(fallback: int = 1) -> int: | |||
# naively use all 24, we'd end up with two threads across the 12 cores. | |||
# This would degrade performance rather than improve it! | |||
return len(os.sched_getaffinity(0)) | |||
except: | |||
else: |
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 semantic change here in the edge case, because os.sched_getaffinity(0)
can fail and raise a Python exception. When it does, Augur will be broken with the change to if/else instead of falling back to os.cpu_count()
with the original try/except.
I think this change should be reverted and mypy appeased another way.
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.
Hooray for types! \o/ |
Description of proposed changes
These changes enforce the types that are sprinkled in the codebase here and there, and ensure future types are checked.
Related issue(s)
--fix-dates
is not specified #1247Testing
What steps should be taken to test the changes you've proposed?
If you added or changed behavior in the codebase, did you update the tests, or do you need help with this?
Checklist