Skip to content

option to enforce error codes in type: ignore comments #11509

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

Closed
DetachHead opened this issue Nov 10, 2021 · 10 comments · Fixed by #11633
Closed

option to enforce error codes in type: ignore comments #11509

DetachHead opened this issue Nov 10, 2021 · 10 comments · Fixed by #11633
Labels

Comments

@DetachHead
Copy link
Contributor

Feature
it would be cool if there was an option like --disallow-ignore-without-code or something that enforces error codes in type: ignore comments

Pitch
# type:ignore comments risk suppressing an unintended error, which is why it's preferred to specify the exact error code you're suppressing

@KotlinIsland
Copy link
Contributor

@asears
Copy link

asears commented Nov 10, 2021

Would also be useful if we could use # type: ignore below comments in the python file. Seems the # type: ignore is ignored if there is a license header in this format. Might be a separate bug/issue here.

# license copyright info
"""This is a file""
# type: ignore

This works.

# type: ignore
# license copyright info
"""This is a file""

The above request seems more like a flake8 check? Maybe in https://pypi.org/project/flake8-annotations/ it would be simpler to implement?

@KotlinIsland
Copy link
Contributor

KotlinIsland commented Nov 11, 2021

@asears What are you talking about? that code looks like a syntax error with an unterminated triple-quoted string.

There are no types in that snipped so how could there be a type error?

@asears
Copy link

asears commented Nov 13, 2021

Just a typo in this github issue, in the full code there is a type error that isn't ignored with the first case and no typos/flake8 warnings. The problem can be reproduced by introducing a type error and trying to silence it with this:

# license copyright info
"""This is a file"""
# type: ignore

Adding the type: ignore to top of file works fine.

@JelleZijlstra
Copy link
Member

@asears this seems unrelated to the proposal. Please open a new issue if you'd like to see a change in mypy.

@KotlinIsland
Copy link
Contributor

@asears are you asking for a whole file type ignore?

In Kotlin annotations can target the file @file:Suppress("UNCHECKED_CAST")

For mypy if that's what you want configure your pyproject.toml to specify the options you want, for eg:

pyproject.toml:

[[tool.mypy.overrides]]
module = "my.module"
ignore_errors = true

@PeterJCLaw
Copy link
Contributor

How should this option interact with file-level # type: ignore comments? Should those be exempt? (Currently it's not possible to specify error codes to ignore per-file, so it feels like it would be hard to require that those ignores have error codes)

@DetachHead
Copy link
Contributor Author

@PeterJCLaw hmm, perhaps a separate option to prohibit file-level ignore comments?

@JelleZijlstra
Copy link
Member

I would not worry about those. If you're using a file-level ignore, you probably want to ignore everything.

@KotlinIsland
Copy link
Contributor

Kotlin handles per code file wide suppression
@file:Suppress("UNCHECKED_CAST"), and I agree.

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

Successfully merging a pull request may close this issue.

5 participants