Skip to content

Move mypy wrapper to tools#54268

Closed
samestep wants to merge 5 commits intopytorch:masterfrom
samestep:move-mypy-wrapper-to-tools
Closed

Move mypy wrapper to tools#54268
samestep wants to merge 5 commits intopytorch:masterfrom
samestep:move-mypy-wrapper-to-tools

Conversation

@samestep
Copy link
Copy Markdown
Contributor

@samestep samestep commented Mar 18, 2021

This PR

  • moves torch/testing/_internal/mypy_wrapper.py (and its accompanying tests from test/test_testing.py) to tools,
  • removes the now-unused test_run_mypy from test/test_type_hints.py, and
  • replaces the hardcoded list of mypy configs (previously duplicated across mypy_wrapper.py and .github/workflows/lint.yml) with a simpler glob

Test plan:

Should also be run in the "Test tools" GHA workflow in CI:

python tools/test/test_mypy_wrapper.py

@samestep samestep requested a review from a team March 18, 2021 19:34
@facebook-github-bot
Copy link
Copy Markdown
Contributor

facebook-github-bot commented Mar 18, 2021

💊 CI failures summary and remediations

As of commit 61c5dc9 (more details on the Dr. CI page):


  • 1/1 failures possibly* introduced in this PR
    • 1/1 non-scanned failure(s)

This comment was automatically generated by Dr. CI (expand for details).Follow this link to opt-out of these comments for your Pull Requests.

Please report bugs/suggestions to the (internal) Dr. CI Users group.

Copy link
Copy Markdown
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@samestep has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Copy link
Copy Markdown
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@samestep has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Copy link
Copy Markdown
Contributor

@janeyx99 janeyx99 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good once you fix flake8

run: |
set -eux
pip install -r requirements.txt
pip install mypy==0.770
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we discussed this before, but why did we decide against having mypy be a requirement?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't remember; @pytorch/pytorch-dev-infra anyone know?

Copy link
Copy Markdown
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@samestep has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Copy link
Copy Markdown
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@samestep has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Copy link
Copy Markdown
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@samestep has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Copy Markdown
Contributor

@samestep merged this pull request in 8cd4dac.

@samestep samestep deleted the move-mypy-wrapper-to-tools branch April 6, 2021 16:38
facebook-github-bot pushed a commit that referenced this pull request Apr 19, 2021
Summary:
#54268 removed `test_run_mypy` since now we're running `mypy` as its own job in GitHub Actions, but previously we used this `set_cwd` context manager in that test to ensure that we picked up the `mypy` config correctly. However, for some reason, we have not been doing that in `test_doc_examples`, which has been succeeding in CI for a while despite being broken.

Specifically, [`run_test.py` changes the working directory to `test/` before running test files](https://github.com/pytorch/pytorch/blob/48aaea3359cffe7982ce24b8742c7a1f4b456a92/test/run_test.py#L534-L535), which is contrary to [what `CONTRIBUTING.md` instructs developers to do](https://github.com/pytorch/pytorch/blob/48aaea3359cffe7982ce24b8742c7a1f4b456a92/CONTRIBUTING.md#python-unit-testing). As a result, in CI, `test/test_type_hints.py` has been passing in CI, but if you run it locally from the root of the repo, this you get this error:
```
F
======================================================================
FAIL: test_doc_examples (__main__.TestTypeHints)
Run documentation examples through mypy.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "test/test_type_hints.py", line 127, in test_doc_examples
    self.fail(f"mypy failed:\n{stdout}")
AssertionError: mypy failed:
test/generated_type_hints_smoketest.py:851: error: Name 'tensor' is not defined  [name-defined]
test/generated_type_hints_smoketest.py:853: error: Name 'tensor' is not defined  [name-defined]
Found 2 errors in 1 file (checked 1 source file)

----------------------------------------------------------------------
Ran 1 test in 1.416s

FAILED (failures=1)
```

Pull Request resolved: #56388

Test Plan:
Before this PR, the first of the following two commands should fail (since that is essentially what is run in CI), but the second should fail:
```
python test/run_test.py -i test_type_hints
python test/test_type_hints.py
```
After this PR, both commands should succeed.

Reviewed By: driazati

Differential Revision: D27860173

Pulled By: samestep

fbshipit-source-id: efb82fffd7ccb04d0331824b40bdef7bbc319c98
krshrimali pushed a commit to krshrimali/pytorch that referenced this pull request May 19, 2021
Summary:
pytorch#54268 removed `test_run_mypy` since now we're running `mypy` as its own job in GitHub Actions, but previously we used this `set_cwd` context manager in that test to ensure that we picked up the `mypy` config correctly. However, for some reason, we have not been doing that in `test_doc_examples`, which has been succeeding in CI for a while despite being broken.

Specifically, [`run_test.py` changes the working directory to `test/` before running test files](https://github.com/pytorch/pytorch/blob/48aaea3359cffe7982ce24b8742c7a1f4b456a92/test/run_test.py#L534-L535), which is contrary to [what `CONTRIBUTING.md` instructs developers to do](https://github.com/pytorch/pytorch/blob/48aaea3359cffe7982ce24b8742c7a1f4b456a92/CONTRIBUTING.md#python-unit-testing). As a result, in CI, `test/test_type_hints.py` has been passing in CI, but if you run it locally from the root of the repo, this you get this error:
```
F
======================================================================
FAIL: test_doc_examples (__main__.TestTypeHints)
Run documentation examples through mypy.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "test/test_type_hints.py", line 127, in test_doc_examples
    self.fail(f"mypy failed:\n{stdout}")
AssertionError: mypy failed:
test/generated_type_hints_smoketest.py:851: error: Name 'tensor' is not defined  [name-defined]
test/generated_type_hints_smoketest.py:853: error: Name 'tensor' is not defined  [name-defined]
Found 2 errors in 1 file (checked 1 source file)

----------------------------------------------------------------------
Ran 1 test in 1.416s

FAILED (failures=1)
```

Pull Request resolved: pytorch#56388

Test Plan:
Before this PR, the first of the following two commands should fail (since that is essentially what is run in CI), but the second should fail:
```
python test/run_test.py -i test_type_hints
python test/test_type_hints.py
```
After this PR, both commands should succeed.

Reviewed By: driazati

Differential Revision: D27860173

Pulled By: samestep

fbshipit-source-id: efb82fffd7ccb04d0331824b40bdef7bbc319c98
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants