Skip to content

Expand type: ignore documentation #11354

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
tusharsadhwani opened this issue Oct 19, 2021 · 3 comments · Fixed by #11358
Closed

Expand type: ignore documentation #11354

tusharsadhwani opened this issue Oct 19, 2021 · 3 comments · Fixed by #11358

Comments

@tusharsadhwani
Copy link
Contributor

Feature

Allowing a short message with your type ignore comments, for better context

Pitch

I wanted to add a little comment with my type: ignore to provide some context as to why that ignore is present in the code.

This is the thing that I tried:

for text in iter(buff.read1, b""):  # type: ignore - typeshed bug
    print(decoder.decode(text), end="")

Unfortunately that doesn't work.
I tried a few other variants, like # type: ignore; typeshed bug, but I could find no way to add a message to the ignore comment.

It also seems like an easy feature that I could work on :)

@emmatyping
Copy link
Member

Per PEP 484:

In some cases, linting tools or other comments may be needed on the same line as a type comment. In these cases, the type comment should be before other comments and linting markers:

# type: ignore # <comment or other marker>

@tusharsadhwani
Copy link
Contributor Author

I wish this was mentioned in mypy docs... perhaps in this section

@emmatyping
Copy link
Member

It is (briefly) covered here, but almost as an aside https://mypy.readthedocs.io/en/stable/cheat_sheet_py3.html#when-you-re-puzzled-or-when-things-are-complicated

If you want to suggest a change in a PR I'm happy to take a look, but I think the bigger issue is we don't really talk much about # type: ignore in the typesystem reference to begin with. It might be useful to add a section about # type: ignore to this page: https://mypy.readthedocs.io/en/stable/type_inference_and_annotations.html#type-inference-and-type-annotations

@emmatyping emmatyping reopened this Oct 19, 2021
@emmatyping emmatyping changed the title Add a message to type: ignore comments Expand type: ignore documentation Oct 19, 2021
emmatyping pushed a commit that referenced this issue Oct 24, 2021
Adds a reference on how # type: ignore can be used.

Resolves #11354
tushar-deepsource pushed a commit to DeepSourceCorp/mypy that referenced this issue Jan 20, 2022
Adds a reference on how # type: ignore can be used.

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

Successfully merging a pull request may close this issue.

2 participants