-
Notifications
You must be signed in to change notification settings - Fork 186
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
Improve mypy type checking #4553
Conversation
Codecov Report
@@ Coverage Diff @@
## develop #4553 +/- ##
===========================================
- Coverage 79.41% 79.41% -0.00%
===========================================
Files 481 481
Lines 35279 35280 +1
===========================================
Hits 28013 28013
- Misses 7266 7267 +1
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
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.
Looks good, thanks @chrisjsewell. I wasn't aware the pre-commit/mirrors-mypy adds a blanket --ignore-missing-imports
, we definitely want to get rid of that.
This PR is blocked until #4534 is merged (which should fix the current errors).
I think it'd be ok to just ignore the migration errors until #4534 is merged, this doesn't necessarily have to block this PR.
By the way, should we also add a |
See https://www.python.org/dev/peps/pep-0561 for guidance. It seems maybe a bit premature to add one yet, given the sparsity of files checked just in .pre-commit-config.yaml (I'll pushing people to add more lol) |
well I'm hoping to merge very soon so might as well wait |
There's this info:
But technically we're not a "stub package" I think - so does this still apply? From this part, it seems to me the annotations should be at least somewhat complete when adding
I guess that makes sense, because otherwise the calling code will get a bunch of errors if |
ok this should be good to go now |
no I don't believe this applies
yeh we can consider this later on, because there is not a whole lot of code that is type checked right now |
Good to go, thanks @chrisjsewell! |
Currently, the mypy in the pre-commit is used as a "non-local" import and adds the blanket
--ignore-missing-imports
flag.This greatly reduces the effectiveness of the type checking, because it does not check any types from classes/functions imported from third-party packages.
For example in #4534 I add the beautifully typed https://github.com/aiidateam/archive-path (note the
py.typed
file in the module signalling it is typed), but the code in aiida-core is not checked against these types at present.Similarly, adding
check_untyped_defs = True
fixes this issue: https://mypy.readthedocs.io/en/stable/common_issues.html#no-errors-reported-for-obviously-wrong-code.This PR is blocked until #4534 is merged (which should fix the current errors).
Note that if we did want to type check against e.g. django there is available stub packages: https://github.com/typeddjango/django-stubs