Skip to content

Add lint for unqualified noqa#56272

Closed
samestep wants to merge 9 commits intopytorch:masterfrom
samestep:lint-unqualified-lint-suppression
Closed

Add lint for unqualified noqa#56272
samestep wants to merge 9 commits intopytorch:masterfrom
samestep:lint-unqualified-lint-suppression

Conversation

@samestep
Copy link
Copy Markdown
Contributor

@samestep samestep commented Apr 16, 2021

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, 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 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.

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:

@facebook-github-bot
Copy link
Copy Markdown
Contributor

facebook-github-bot commented Apr 16, 2021

💊 CI failures summary and remediations

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


💚 💚 Looks good so far! There are no failures yet. 💚 💚


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.

@samestep samestep changed the title Add lints for unqualified noqa and type: ignore Add lint for unqualified noqa Apr 16, 2021
@facebook-github-bot
Copy link
Copy Markdown
Contributor

@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 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.

What cool features are we missing without using flake8-noqa? This current lint seems functional enough.

@samestep
Copy link
Copy Markdown
Contributor Author

What cool features are we missing without using flake8-noqa? This current lint seems functional enough.

@janeyx99 This git grep-based lint misses out on the following flake8-noqa error codes (I've copied just the relevant subset of the table here):

Code Message
NQA005 "# noqa: X000, X000" has duplicate codes, remove X000
NQA102 "# noqa: X000" has no matching violations
NQA103 "# noqa: X000, X001" has unmatched code(s), remove X001

@facebook-github-bot
Copy link
Copy Markdown
Contributor

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

@janeyx99
Copy link
Copy Markdown
Contributor

What cool features are we missing without using flake8-noqa? This current lint seems functional enough.

@janeyx99 This git grep-based lint misses out on the following flake8-noqa error codes (I've copied just the relevant subset of the table here):

Code
Message

NQA005
"# noqa: X000, X000" has duplicate codes, remove X000

NQA102
"# noqa: X000" has no matching violations

NQA103
"# noqa: X000, X001" has unmatched code(s), remove X001

Yea I just tried the flake8-noqa locally and it did not output any errors for me either :/

@facebook-github-bot
Copy link
Copy Markdown
Contributor

@samestep merged this pull request in e3900d2.

@samestep samestep deleted the lint-unqualified-lint-suppression branch April 19, 2021 20:19
facebook-github-bot pushed a commit that referenced this pull request Apr 21, 2021
Summary:
The other half of #56272.

Pull Request resolved: #56290

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

- https://github.com/pytorch/pytorch/runs/2384511062
- https://github.com/pytorch/pytorch/actions/runs/765036024

Reviewed By: seemethere

Differential Revision: D27867219

Pulled By: samestep

fbshipit-source-id: e648f07b6822867e70833e23ddafe7fb7eaca235
heitorschueroff pushed a commit that referenced this pull request Apr 21, 2021
Summary:
The other half of #56272.

Pull Request resolved: #56290

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

- https://github.com/pytorch/pytorch/runs/2384511062
- https://github.com/pytorch/pytorch/actions/runs/765036024

Reviewed By: seemethere

Differential Revision: D27867219

Pulled By: samestep

fbshipit-source-id: e648f07b6822867e70833e23ddafe7fb7eaca235
krshrimali pushed a commit to krshrimali/pytorch that referenced this pull request May 19, 2021
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: pytorch#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
krshrimali pushed a commit to krshrimali/pytorch that referenced this pull request May 19, 2021
Summary:
The other half of pytorch#56272.

Pull Request resolved: pytorch#56290

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

- https://github.com/pytorch/pytorch/runs/2384511062
- https://github.com/pytorch/pytorch/actions/runs/765036024

Reviewed By: seemethere

Differential Revision: D27867219

Pulled By: samestep

fbshipit-source-id: e648f07b6822867e70833e23ddafe7fb7eaca235
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