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

incorrect 'error: Unnecessary "# type: ignore" comment' #4294

Closed
akirakoyasu opened this issue Dec 7, 2022 · 3 comments
Closed

incorrect 'error: Unnecessary "# type: ignore" comment' #4294

akirakoyasu opened this issue Dec 7, 2022 · 3 comments
Labels
as designed Not a bug, working as intended

Comments

@akirakoyasu
Copy link

akirakoyasu commented Dec 7, 2022

Note: if you are reporting a wrong signature of a function or a class in the standard library, then the typeshed tracker is better suited for this report: https://github.com/python/typeshed/issues.

Describe the bug
pyright 1.1.283 reports incorrect 'error: Unnecessary "# type: ignore" comment' in commented out code.

Enhancement of 1.1.283
Added support for # pyright: ignore and # type: ignore comments that are not at the start of a comment.
produces this bug?

To Reproduce
Check this snippet by pyright 1.1.283

# fileConfig(config.config_file_name)  # type: ignore

Expected behavior
"# type: ignore" comment in commented out code should be ignored.

@erictraut
Copy link
Collaborator

Yes, this is intended behavior. This is a side effect of a recent change. Previously, # pyright: ignore and # type: ignore were honored only when there were located at the beginning of a comment. They are now honored anywhere within a comment. That means the code in your sample is considered an unnecessary use of # type: ignore and will be flagged as such by the reportUnnecessaryTypeIgnoreComment diagnostic check. You would have seen the same behavior prior to 1.1.283 if you had used a # type: ignore by itself on a line.

@erictraut erictraut added the as designed Not a bug, working as intended label Dec 7, 2022
@Jeremiah-England
Copy link

It would be nice if you could comment out a block of code without getting "information" warnings about reportUnnecessaryTypeIgnoreComment. Those warnings clutter up the output. But it doesn't make sense to remove from from the commented out block because you will need to add them back when you uncomment it.

Is ignoring this warning if the entire line is just a comment possible?

@jdanbrown
Copy link

It would be nice if you could comment out a block of code without getting "information" warnings about reportUnnecessaryTypeIgnoreComment. Those warnings clutter up the output. But it doesn't make sense to remove from from the commented out block because you will need to add them back when you uncomment it.

Yeah, as a pyright user I strongly agree with this — when you comment out a block of code you want it to be... commented out, as if it doesn't exist. You don't want your type checker to complain that something is wrong with it.

What's the rationale for flagging # type: ignore comments as unnecessary in commented-out code? Based on the discussion above I don't understand why this is a helpful behavior, it seems to me like only a harmful behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
as designed Not a bug, working as intended
Projects
None yet
Development

No branches or pull requests

4 participants