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

Warn about unused '# type: ignore' comments #1695

Merged
merged 1 commit into from
Jun 22, 2016

Conversation

rwbarton
Copy link
Contributor

Still needs tests and some cleanup.

@rwbarton
Copy link
Contributor Author

The results on mypy itself, for those curious:

rbarton-mbp:mypy rbarton$ python3 -m mypy --warn-unused-ignores mypy
typeshed/stdlib/3/builtins.pyi:406: note: unused 'type: ignore' comment
typeshed/stdlib/3/io.pyi:230: note: unused 'type: ignore' comment
typeshed/stdlib/3/io.pyi:231: note: unused 'type: ignore' comment
typeshed/stdlib/3/io.pyi:236: note: unused 'type: ignore' comment
mypy/errors.py:395: note: unused 'type: ignore' comment
mypy/main.py:133: note: unused 'type: ignore' comment

@gvanrossum
Copy link
Member

I can't wait to use this!

Unfortunately there's also #1294 which someone at the sprints was going to tackle (though they haven't sent a PR yet). Wouldn't it be confusing if these notes appeared at the end and out of order? (Then again, out of order is better than not at all.)

@gvanrossum
Copy link
Member

Be sure to add "Fixes #1345" to the commit when merging.

Consider combining this with #958 and changing the flag name to be less specific.

@rwbarton
Copy link
Contributor Author

I made a separate PR (#1705) for redundant casts since that one is actually much simpler. I'm happy to have these two flags controlled by the same command-line option if someone wants to suggest a name :)

Unfortunately there's also #1294 which someone at the sprints was going to tackle (though they haven't sent a PR yet). Wouldn't it be confusing if these notes appeared at the end and out of order? (Then again, out of order is better than not at all.)

I thought about that PR, but I'd rather not block this on waiting for that one, and as you say a confusing message order is better than not having the messages at all. With that PR it'd certainly make sense to generate the unused # type: ignore warnings per-SCC rather than all at the end, though.

@gvanrossum
Copy link
Member

Curious, what is this waiting on? I really want this feature!

@rwbarton
Copy link
Contributor Author

Oh, thanks for the reminder about this one. When I wrote this I didn't know how to write tests that set build flags, but I do now (using # flags: ...). There are also some edge cases involving # type: ignore comments on import statements that I want to take another look at.

@gvanrossum
Copy link
Member

gvanrossum commented Jun 21, 2016 via email

@rwbarton
Copy link
Contributor Author

This still needs new tests (will add them a bit later) but I'm much happier with this version which handles ignored_lines in a simpler and more uniform way (adding them once to the Errors object after parsing).

@rwbarton rwbarton changed the title WIP: Warn on unused # type: ignores Warn about unused '# type: ignore' comments Jun 22, 2016
@rwbarton
Copy link
Contributor Author

OK, this should be ready to go except that one of the new tests fails for now; I filed #1737 to fix it separately because I'm not 100% sure I understand what is going on there. That PR should be landed (or otherwise resolved somehow) before this one.

This commit also simplifies the handling of ignored_lines slightly,
setting them once in the Errors object for each file file after it is
parsed.

Fixes python#1345 and python#1739.
@rwbarton
Copy link
Contributor Author

OK, #1737 was wrong, so another try. I made it never warn about # type: ignore comments on imports since that is simple and probably correct most of the time anyways. In order to do that, it was convenient to fix #1739 at the same time.

@gvanrossum
Copy link
Member

There's a problem with this PR that we discovered today: #1911. In an attempt to make it so that you can use # type: ignore on an import to silence a module with a syntax error (or perhaps with any kind of error), this PR accidentally makes mypy entirely ignore any line of the form import x # type: ignore (or similar for import as). That can't be the intention! We're fixing that in #1912. @rwbarton: holler now if you think we're making a grave mistake.

@rwbarton
Copy link
Contributor Author

Well that's what I intended and I think what the old behavior was (though maybe not with the fast parser): see discussion at #1737. But the new behavior seems fine to me too.

@gvanrossum
Copy link
Member

gvanrossum commented Jul 19, 2016 via email

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

Successfully merging this pull request may close these issues.

2 participants