pytorch/torch/jit
Sam Estep e3900d2ba5 Add lint for unqualified noqa (#56272)
Summary:
As this diff shows, currently there are a couple hundred instances of raw `noqa` in the codebase, which just ignore all errors on a given line. That isn't great, so this PR changes all existing instances of that antipattern to qualify the `noqa` with respect to a specific error code, and adds a lint to prevent more of this from happening in the future.

Interestingly, some of the examples the `noqa` lint catches are genuine attempts to qualify the `noqa` with a specific error code, such as these two:
```
test/jit/test_misc.py:27:            print(f"{hello + ' ' + test}, I'm a {test}") # noqa E999
test/jit/test_misc.py:28:            print(f"format blank") # noqa F541
```
However, those are still wrong because they are [missing a colon](https://flake8.pycqa.org/en/3.9.1/user/violations.html#in-line-ignoring-errors), which actually causes the error code to be completely ignored:

- If you change them to anything else, the warnings will still be suppressed.
- If you add the necessary colons then it is revealed that `E261` was also being suppressed, unintentionally:
  ```
  test/jit/test_misc.py:27:57: E261 at least two spaces before inline comment
  test/jit/test_misc.py:28:35: E261 at least two spaces before inline comment
  ```

I did try using [flake8-noqa](https://pypi.org/project/flake8-noqa/) instead of a custom `git grep` lint, but it didn't seem to work. This PR is definitely missing some of the functionality that flake8-noqa is supposed to provide, though, so if someone can figure out how to use it, we should do that instead.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/56272

Test Plan:
CI should pass on the tip of this PR, and we know that the lint works because the following CI run (before this PR was finished) failed:

- https://github.com/pytorch/pytorch/runs/2365189927

Reviewed By: janeyx99

Differential Revision: D27830127

Pulled By: samestep

fbshipit-source-id: d6dcf4f945ebd18cd76c46a07f3b408296864fcb
2021-04-19 13:16:18 -07:00
..
mobile [Pytorch Mobile] Expose _export_operator_list to python (#51312) 2021-02-01 12:09:02 -08:00
__init__.py Merge CUDA Streams and Events (#53902) 2021-04-05 08:19:55 -07:00
_async.py fix fork formatting (#49436) 2021-01-05 16:38:34 -08:00
_builtins.py Add JIT support for cmath unary ops (#54089) 2021-03-26 22:55:34 -07:00
_check.py Walk Python AST to check for unsupported attribute type annotations (#51805) 2021-02-12 18:18:01 -08:00
_freeze.py Forbid trailing whitespace (#53406) 2021-03-05 17:22:55 -08:00
_fuser.py Ge v1 (#52136) 2021-02-28 00:53:13 -08:00
_logging.py
_pickle.py
_recursive.py Upgrade mypy to version 0.812 (#55712) 2021-04-12 18:08:28 -07:00
_script.py Better types in fbcode/caffe2/torch/jit/_script.py (#55856) 2021-04-13 11:46:23 -07:00
_serialization.py [*.py] Rename "Arguments:" to "Args:" (#49736) 2020-12-28 09:34:47 -08:00
_state.py [package] fix mangling issues with TorchScript (#54915) 2021-03-31 00:58:05 -07:00
_trace.py make torch.testing asserts importable (#54769) 2021-04-07 23:53:02 -07:00
annotations.py Add lint for unqualified noqa (#56272) 2021-04-19 13:16:18 -07:00
frontend.py [JIT] Put explicit error message on class attribute accesses. (#55723) 2021-04-16 15:47:10 -07:00
quantized.py Add lint for unqualified noqa (#56272) 2021-04-19 13:16:18 -07:00
supported_ops.py Add lint for unqualified noqa (#56272) 2021-04-19 13:16:18 -07:00
unsupported_tensor_ops.py