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

Idea: issue an error if a '# type: ignore' comment is unused #1345

Closed
gvanrossum opened this issue Apr 7, 2016 · 8 comments
Closed

Idea: issue an error if a '# type: ignore' comment is unused #1345

gvanrossum opened this issue Apr 7, 2016 · 8 comments
Assignees

Comments

@gvanrossum
Copy link
Member

Sometimes we put in # type: ignore comments because of some mypy or typeshed bug (or a missing feature). It would be nice if mypy told us when we can take those out (e.g. because the bug is fixed).

Maybe this should be a command-line flag, I can imagine it might be annoying occasionally too.

@ddfisher
Copy link
Collaborator

ddfisher commented Apr 8, 2016

This is a good idea! I think it should definitely be behind a flag, though -- it'd be annoying to cause errors in people's code whenever we fix a bug. Also, they may need the code to work across multiple mypy versions for some reason, which this would disallow. The fast parser transition is a concrete example: because it can change the line errors are assigned to, you'll need some extraneous type ignores during the transition period.

@gvanrossum
Copy link
Member Author

It was @rwbarton's suggestion -- IIRC he said GHC has this.

--Guido (mobile)
On Apr 7, 2016 5:10 PM, "David Fisher" notifications@github.com wrote:

This is a good idea! I think it should definitely be behind a flag, though
-- it'd be annoying to cause errors in people's code whenever we fix a bug.
Also, they may need the code to work across multiple mypy versions for some
reason, which this would disallow. The fast parser transition is a concrete
example: because it can change the line errors are assigned to, you'll need
some extraneous type ignores during the transition period.


You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub
#1345 (comment)

@ddfisher
Copy link
Collaborator

ddfisher commented Jun 4, 2016

I think it's become clear that this is a good idea to have available behind a flag. I think I'd discourage running with this on in CI (because sometimes you need unused # type: ignores for forward compatibility), but it would be great to have for periodic sweeps.

@gvanrossum
Copy link
Member Author

Yes!

@rwbarton rwbarton modified the milestones: 0.4.x, Future Jun 9, 2016
@rwbarton rwbarton self-assigned this Jun 9, 2016
@rwbarton
Copy link
Contributor

rwbarton commented Jun 9, 2016

Even a simple version of this behind a flag will be useful, and I sort of promised this to the Zulip people, so I'll take a shot at this in the near future (traveling again this weekend but will still have time for mypy work).

@wittekm
Copy link
Contributor

wittekm commented Jun 11, 2016

Potentially related request: could the same thing be accomplished for superfluous cast(some_obj, SomeType) when some_obj is already guaranteed to be SomeType?

(Sample use case: in our codebase, we were doing a lot of IntEnum casting due to a mypy bug that was just fixed).

@ddfisher
Copy link
Collaborator

Sounds like a good idea to me -- could even be the same flag, IMO.

On Fri, Jun 10, 2016 at 5:29 PM, Max Wittek notifications@github.com
wrote:

Potentially related request: could the same thing be accomplished for
superfluous cast(some_obj, SomeType) when some_obj is already guaranteed to
be SomeType?


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#1345 (comment), or mute
the thread
https://github.com/notifications/unsubscribe/AAPAkUcfG-aeShbdOV8d9JgY6ODZ11pvks5qKgFqgaJpZM4IClTg
.

@rwbarton
Copy link
Contributor

could the same thing be accomplished for superfluous cast(some_obj, SomeType) when some_obj is already guaranteed to be SomeType?

Yes! In fact, that is #958. Mypy itself has many redundant casts from before mypy understood isinstance checks; I removed about 60 of them a while ago but I'm sure there are a lot more.

rwbarton added a commit to rwbarton/mypy that referenced this issue Jun 22, 2016
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.
rwbarton added a commit to rwbarton/mypy that referenced this issue Jun 22, 2016
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.
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

No branches or pull requests

4 participants