-
Notifications
You must be signed in to change notification settings - Fork 37.6k
test: Mypy next steps #19532
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
test: Mypy next steps #19532
Conversation
The data package needs this file to be identified as a package directory for import
Generate necessary stub files for mypy checks.
Generate necessary stub files for mypy checks.
Remove --ignore-missing-imports flag from call to mypy and set MYPYPATH variable for stub file recognition.
@@ -714,7 +714,7 @@ def _initialize_chain_clean(self): | |||
def skip_if_no_py3_zmq(self): | |||
"""Attempt to import the zmq package and skip the test if the import fails.""" | |||
try: | |||
import zmq # noqa | |||
import zmq # type:ignore |
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.
This line appears to be getting caught in the linter.
test/functional/test_framework/test_framework.py:717:13: F401 'zmq' imported but unused
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.
As far as I can tell, we don't be able to fix this short of disabling flake8 linting for the entire file. It's a false positive, in this case the very act of importing the module is "using" it.
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.
It's worth noting that this brings us from 3 F401
warnings up to 4 F401
warnings.
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.
is it not possible to keep the # noqa
linter disable comment?
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.
Unfortunately not. We need the type:ignore
or else MyPy fails completely. I've tried things like putting them both on the same line but it looks like flake8 and MyPy just don't play nicely together in this sort of conflict.
Worth noting maybe that pylint allows us to disable a particular linting error for an entire function (which would fix this problem), where AFAICT flake8 does not.
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.
that's unfortunate :(
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.
Unfortunately not. We need the type:ignore or else MyPy fails completely. I've tried things like putting them both on the same line but it looks like flake8 and MyPy just don't play nicely together in this sort of conflict.
Just to clarify: https://mypy.readthedocs.io/en/stable/common_issues.html#silencing-linters - this does not work? Is it what you have tried?
This all looks great! However, try as I might, I can't get MyPy to ever actually tell me something is wrong. (i.e. I intentionally give a function an argument with the wrong type and MyPy still passes every file) Have you been able to? Regarding your concern here that this isn't python 3.5 compatible, I don't think you have to worry. The only parts that aren't compatible are the |
Thanks for taking the time to review the code! When I run the linter file (lint-python.py), Mypy doesn't catch any errors, however, when I run mypy from the command line as such: |
I'm new to mypy, but I found this issue which seems to address the problem that was previously encountered. It seems like the To test this, I included the |
@adaminsky thanks for looking at this! Great to see that we might not need the stub files after all! I don't think we're all the way there yet thought, creating Did you try making a type error inside a test in |
I've tried changing MyPy's configuration options, maybe that will do the trick. To try this too, create a config file, say,
Then running MyPy with |
@troygiorshev I mislabeled the types in the |
I understand mypy is desirable for type checking, but I see a potential maintainability issue with the stub files: many changes to the test framework will now require updating these files as well. I'm not sure we should be putting this burden on every contributor. |
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
🐙 This pull request conflicts with the target branch and needs rebase. Want to unsubscribe from rebase notifications on this pull request? Just convert this pull request to a "draft". |
@ghorbanian thanks for your work here, but I agree with @laanwj in regards to the maintenance overhead of adding these stubs. Since this PR was opened, there have been upstream changes which have negated the needs for some of the commits here, such as ignoring the zmq imports (the pyzmq package now comes with stubs). I'm going to close this PR, and I think we can renew discussion in #19389, and potentially make some other mypy related changes in the mean time. |
Generate stub files for data and test_framework packages. Set MYPYPATH variable to allow recognition of the aforementioned stub files while ignoring the zmq import that causes an error while running mypy. Fixes issue #19389.