Skip to content
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

support for # type: ignore #164

Closed
martinResearch opened this issue May 1, 2024 · 5 comments · Fixed by #165
Closed

support for # type: ignore #164

martinResearch opened this issue May 1, 2024 · 5 comments · Fixed by #165
Labels
enhancement New feature or request

Comments

@martinResearch
Copy link

Description
An option to parse "# type: ignore" comments and disable the flake8-annotations checks on the corresponding lines of code.

Rationale/Use Case
I am currently using mypy to check the type annotations on a large code base, but that is slow to run. I would like to use flake8-annotations (or the ruff re-implementation) before calling mypy in order to be able to catch missing annotation faster than with mypy and thus to be able to iterate faster.
My code contains quite a few "# type: ignore" comments that are currently ignored by flake8-annotations, which gives me many errors when using flake8-annotations while mypy does not raise any error. I would like to have the option to tell flake8-annotations to detect "# type: ignore" comments so that, like mypy, it does not check the corresponding lines and so that I can get flake8-annotations check passing on that code without having to modify the code on each line where I currently use # type: ignore.

@martinResearch martinResearch added the enhancement New feature or request label May 1, 2024
@sco1
Copy link
Owner

sco1 commented May 1, 2024

I can see this being interesting, and shouldn't be too difficult to explore since ast parses these comment locations already. I think it would have to be opt-in because we would not be able to do anything about specific ignore codes, e.g. # type: ignore[arg-type] would be treated the same as # type: ignore, which could be an annoying caveat for many. I will try to explore later this week.

(or the ruff re-implementation)

As an aside, it's worth noting that I do not have any influence on this implementation, this is wholly Astral's work and under their editorial control. If you'd like to use the ruff plugin you'll need to request this feature there as well.

@martinResearch
Copy link
Author

"If you'd like to use the ruff plugin you'll need to request this feature there as well." Understood. I believe that having the new option in flake8-annotations would help in motivating the implementation of an equivalent option in ruff.

@sco1 sco1 mentioned this issue May 2, 2024
@sco1 sco1 closed this as completed in #165 May 6, 2024
@sco1
Copy link
Owner

sco1 commented May 6, 2024

This should be available now to try out. I don't have a large amount of latent code to explore this with so please let me know if there are any issues.

@martinResearch
Copy link
Author

I tried and it seem to work as expected:). I am still getting some errors in my code base in places mypy does not give me any error. The two type of errors are due to two reasons

  • # type: ignore can be added at the beginning of a file in which case mypy while ignore type errors in the entire file. In contrast, Flake8-annotations will not apply the ignore to the entire file.
  • mypy does not complain about missing annotation for the the first argument in class methods (usually self) while Flake8-annotations does.

@sco1
Copy link
Owner

sco1 commented May 7, 2024

The first should be easy to add, I'll make another issue to track. For the second, it sounds like you want to ignore ANN101 (See: #75).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants