idea: add a toggle so that pyright ignores narrowed mypy type:ignore annotations #8863
danielbprice
started this conversation in
Ideas
Replies: 1 comment 1 reply
-
Pyright provides a setting |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I recently reviewed the open issues and forum discussions about the issues over the interpretation of
type: ignore
comments. I maintain a source base where Pyright is the primary type checker but at times we also run mypy to see if it finds anything else.A typical example from our source code would be:
mypy also finds and surfaces this non-issue. I could simply add
type: ignore
to silence both checkers but as a long time user of lint and other checking tools, I feel strongly that the best practice is to silence just the specific error; this also helps the code be more self-documenting.The issues here stem from mypy's non-standard extension
# type: ignore[specific-issue]
. This is discussed here: python/mypy#12358 and elsewhere. I can't add# type: ignore[something-specific-to-mypy]
without pyright treating this as# type: ignore
(suppress all issues). mypy is (dubiously) extending the spec, and pyright is trying to adhere to the spec as written.After reviewing the differences of opinion between the various parties, I wondered if Pyright could bend slightly here, and add a small configuration knob to say: if I see a narrowed mypy
# type: ignore[something]
statement, instead of treating it as a valid PEP484 comment, treat it as invalid. And drop it on the floor. Then it would be possible to have:A user who opts to stick
type: ignore
here, without the mypy-specific narrowing, would have things work as before. Something likeignore_mypy_extended_type_ignores = true
(uhh, naming is hard).I realize that this request is putting the onus on Pyright to solve a problem caused by mypy, but I didn't see this suggestion in the previous discussions, and I thought it might provide an escape hatch for everyone who is affected until such time as mypy implements
mypy:
comments or a new PEP with further clarifications is produced.Thanks. One way or another, I really appreciate this tool!
Beta Was this translation helpful? Give feedback.
All reactions