[reland] Refactor mypy configs list into editor-friendly wrapper#50826
[reland] Refactor mypy configs list into editor-friendly wrapper#50826samestep wants to merge 4 commits intopytorch:masterfrom samestep:refactor-mypy-tests-into-wrapper
Conversation
facebook-github-bot
left a comment
There was a problem hiding this comment.
@samestep has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
facebook-github-bot
left a comment
There was a problem hiding this comment.
@samestep has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
|
This PR is making me wonder if there isn't a way to have a single unified mypy configuration, so you no longer need to do have a script groveling through the ini files to work out which configuration should be used in. I will admit that when I added mypy-strict.ini, I didn't know very much about how mypy config files worked, and just did the thing that I knew would work for making stricter checking happen. |
|
@ezyang I'd be up for unifying the configs if it's possible, since ideally it'd be good not to incur the complexity cost this PR adds (or more accurately, the existing complexity of having multiple
If we resolve point 1 but not point 2 then I'd still need part of the functionality of the |
|
I see this |
facebook-github-bot
left a comment
There was a problem hiding this comment.
@samestep has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
rgommers
left a comment
There was a problem hiding this comment.
This simplifies the test file, so LGTM modulo my minor comments. The manual test plan plus CI passing seems fine to me.
facebook-github-bot
left a comment
There was a problem hiding this comment.
@samestep has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
facebook-github-bot
left a comment
There was a problem hiding this comment.
@samestep has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
|
Reverting this PR because its |
facebook-github-bot
left a comment
There was a problem hiding this comment.
@samestep has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
Codecov Report
@@ Coverage Diff @@
## master #50826 +/- ##
==========================================
- Coverage 80.99% 80.98% -0.01%
==========================================
Files 1916 1917 +1
Lines 209552 209585 +33
==========================================
+ Hits 169736 169742 +6
- Misses 39816 39843 +27 |
Summary: Closes pytorch#50513 by resolving the first three checkboxes. If this PR is merged, I will also modify one or both of the following wiki pages to add instructions on how to use this `mypy` wrapper for VS Code editor integration: - [Guide for adding type annotations to PyTorch](https://github.com/pytorch/pytorch/wiki/Guide-for-adding-type-annotations-to-PyTorch) - [Lint as you type](https://github.com/pytorch/pytorch/wiki/Lint-as-you-type) The test plan below is fairly manual, so let me know if I should add more automated tests to this PR. Pull Request resolved: pytorch#50826 Test Plan: Unit tests for globbing function: ``` python test/test_testing.py TestMypyWrapper -v ``` Manual checks: - Uninstall `mypy` and run `python test/test_type_hints.py` to verify that it still works when `mypy` is absent. - Reinstall `mypy` and run `python test/test_type_hints.py` to verify that this didn't break the `TestTypeHints` suite. - Run `python test/test_type_hints.py` again (should finish quickly) to verify that this didn't break `mypy` caching. - Run `torch/testing/_internal/mypy_wrapper.py` on a few Python files in this repo to verify that it doesn't give any additional warnings when the `TestTypeHints` suite passes. Some examples (compare with the behavior of just running `mypy` on these files): ```sh torch/testing/_internal/mypy_wrapper.py README.md torch/testing/_internal/mypy_wrapper.py tools/fast_nvcc/fast_nvcc.py torch/testing/_internal/mypy_wrapper.py test/test_type_hints.py torch/testing/_internal/mypy_wrapper.py torch/random.py torch/testing/_internal/mypy_wrapper.py torch/testing/_internal/mypy_wrapper.py ``` - Remove type hints from `torch.testing._internal.mypy_wrapper` and verify that running `mypy_wrapper.py` on that file gives type errors. - Remove the path to `mypy_wrapper.py` from the `files` setting in `mypy-strict.ini` and verify that running it again on itself no longer gives type errors. - Add `test/test_type_hints.py` to the `files` setting in `mypy-strict.ini` and verify that running the `mypy` wrapper on it again now gives type errors. - Remove type hints from `torch/random.py` and verify that running the `mypy` wrapper on it again now gives type errors. - Add the suggested JSON from the docstring of `torch.testing._internal.mypy_wrapper.main` to your `.vscode/settings.json` and verify that VS Code gives the same results (inline, while editing any Python file in the repo) as running the `mypy` wrapper on the command line, in all the above cases. Reviewed By: glaringlee, walterddr Differential Revision: D25977352 Pulled By: samestep fbshipit-source-id: 4b3a5e8a9071fcad65a19f193bf3dc7dc3ba1b96
…orch#50826) Summary: Closes pytorch#50513 by resolving all four checkboxes. If this PR is merged, I will also modify one or both of the following wiki pages to add instructions on how to use this `mypy` wrapper for VS Code editor integration: - [Guide for adding type annotations to PyTorch](https://github.com/pytorch/pytorch/wiki/Guide-for-adding-type-annotations-to-PyTorch) - [Lint as you type](https://github.com/pytorch/pytorch/wiki/Lint-as-you-type) Pull Request resolved: pytorch#50826 Test Plan: Unit tests for globbing function: ``` python test/test_testing.py TestMypyWrapper -v ``` Manual checks: - Uninstall `mypy` and run `python test/test_type_hints.py` to verify that it still works when `mypy` is absent. - Reinstall `mypy` and run `python test/test_type_hints.py` to verify that this didn't break the `TestTypeHints` suite. - Run `python test/test_type_hints.py` again (should finish quickly) to verify that this didn't break `mypy` caching. - Run `torch/testing/_internal/mypy_wrapper.py` on a few Python files in this repo to verify that it doesn't give any additional warnings when the `TestTypeHints` suite passes. Some examples (compare with the behavior of just running `mypy` on these files): ```sh torch/testing/_internal/mypy_wrapper.py $PWD/README.md torch/testing/_internal/mypy_wrapper.py $PWD/tools/fast_nvcc/fast_nvcc.py torch/testing/_internal/mypy_wrapper.py $PWD/test/test_type_hints.py torch/testing/_internal/mypy_wrapper.py $PWD/torch/random.py torch/testing/_internal/mypy_wrapper.py $PWD/torch/testing/_internal/mypy_wrapper.py ``` - Remove type hints from `torch.testing._internal.mypy_wrapper` and verify that running `mypy_wrapper.py` on that file gives type errors. - Remove the path to `mypy_wrapper.py` from the `files` setting in `mypy-strict.ini` and verify that running it again on itself no longer gives type errors. - Add `test/test_type_hints.py` to the `files` setting in `mypy-strict.ini` and verify that running the `mypy` wrapper on it again now gives type errors. - Change a return type in `torch/random.py` and verify that running the `mypy` wrapper on it again now gives type errors. - Add the suggested JSON from the docstring of `torch.testing._internal.mypy_wrapper.main` to your `.vscode/settings.json` and verify that VS Code gives the same results (inline, while editing any Python file in the repo) as running the `mypy` wrapper on the command line, in all the above cases. Reviewed By: walterddr Differential Revision: D26049052 Pulled By: samestep fbshipit-source-id: 0b35162fc78976452b5ea20d4ab63937b3c7695d
Closes #50513 by resolving all four checkboxes. If this PR is merged, I will also modify one or both of the following wiki pages to add instructions on how to use this
mypywrapper for VS Code editor integration:Test plan:
Unit tests for globbing function:
Manual checks:
mypyand runpython test/test_type_hints.pyto verify that it still works whenmypyis absent.mypyand runpython test/test_type_hints.pyto verify that this didn't break theTestTypeHintssuite.python test/test_type_hints.pyagain (should finish quickly) to verify that this didn't breakmypycaching.torch/testing/_internal/mypy_wrapper.pyon a few Python files in this repo to verify that it doesn't give any additional warnings when theTestTypeHintssuite passes. Some examples (compare with the behavior of just runningmypyon these files):torch.testing._internal.mypy_wrapperand verify that runningmypy_wrapper.pyon that file gives type errors.mypy_wrapper.pyfrom thefilessetting inmypy-strict.iniand verify that running it again on itself no longer gives type errors.test/test_type_hints.pyto thefilessetting inmypy-strict.iniand verify that running themypywrapper on it again now gives type errors.torch/random.pyand verify that running themypywrapper on it again now gives type errors.torch.testing._internal.mypy_wrapper.mainto your.vscode/settings.jsonand verify that VS Code gives the same results (inline, while editing any Python file in the repo) as running themypywrapper on the command line, in all the above cases.