-
Notifications
You must be signed in to change notification settings - Fork 2k
type: ignore[codes] and knot: ignore
#15078
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
crates/red_knot_python_semantic/resources/mdtest/suppressions/knot-ignore.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| # Suppressing errors with `knot: ignore` | ||
|
|
||
| Type check errors can be suppressed by a `knot: ignore` comment on the same line as the violation. | ||
|
|
||
| ## Simple `knot: ignore` | ||
|
|
||
| ```py | ||
| a = 4 + test # knot: ignore | ||
| ``` | ||
|
|
||
| ## Suppressing a specific code | ||
|
|
||
| ```py | ||
| a = 4 + test # knot: ignore[unresolved-reference] | ||
| ``` | ||
|
|
||
| ## Useless suppression | ||
|
|
||
| TODO: Red Knot should emit an `unused-suppression` diagnostic for the | ||
| `possibly-unresolved-reference` suppression. | ||
|
|
||
| ```py | ||
| test = 10 | ||
| a = test + 3 # knot: ignore[possibly-unresolved-reference] | ||
| ``` | ||
|
|
||
| ## Useless suppression if the error codes don't match | ||
|
|
||
| TODO: Red Knot should emit a `unused-suppression` diagnostic for the `possibly-unresolved-reference` | ||
| suppression because it doesn't match the actual `unresolved-reference` diagnostic. | ||
|
|
||
| ```py | ||
| # error: [unresolved-reference] | ||
| a = test + 3 # knot: ignore[possibly-unresolved-reference] | ||
| ``` | ||
|
|
||
| ## Multiple suppressions | ||
|
|
||
| ```py | ||
| # fmt: off | ||
| def test(a: f"f-string type annotation", b: b"byte-string-type-annotation"): ... # knot: ignore[fstring-type-annotation, byte-string-type-annotation] | ||
| ``` | ||
|
|
||
| ## Can't suppress syntax errors | ||
|
|
||
| <!-- blacken-docs:off --> | ||
|
|
||
| ```py | ||
| # error: [invalid-syntax] | ||
| def test( # knot: ignore | ||
| ``` | ||
|
|
||
| <!-- blacken-docs:on --> | ||
|
|
||
| ## Can't suppress `revealed-type` diagnostics | ||
|
|
||
| ```py | ||
| a = 10 | ||
| # revealed: Literal[10] | ||
| reveal_type(a) # knot: ignore | ||
| ``` | ||
|
|
||
| ## Extra whitespace in type ignore comments is allowed | ||
|
|
||
| ```py | ||
| a = 10 / 0 # knot : ignore | ||
| a = 10 / 0 # knot: ignore [ division-by-zero ] | ||
| ``` | ||
|
|
||
| ## Whitespace is optional | ||
|
|
||
| ```py | ||
| # fmt: off | ||
| a = 10 / 0 #knot:ignore[division-by-zero] | ||
| ``` | ||
|
|
||
| ## Trailing codes comma | ||
|
|
||
| Trailing commas in the codes section are allowed: | ||
|
|
||
| ```py | ||
| a = 10 / 0 # knot: ignore[division-by-zero,] | ||
| ``` | ||
|
|
||
| ## Invalid characters in codes | ||
|
|
||
| ```py | ||
| # error: [division-by-zero] | ||
| a = 10 / 0 # knot: ignore[*-*] | ||
| ``` | ||
|
|
||
| ## Trailing whitespace | ||
|
|
||
| <!-- blacken-docs:off --> | ||
|
|
||
| ```py | ||
| a = 10 / 0 # knot: ignore[division-by-zero] | ||
| # ^^^^^^ trailing whitespace | ||
| ``` | ||
|
|
||
| <!-- blacken-docs:on --> | ||
|
|
||
| ## Missing comma | ||
|
|
||
| A missing comma results in an invalid suppression comment. We may want to recover from this in the | ||
| future. | ||
|
|
||
| ```py | ||
| # error: [unresolved-reference] | ||
| a = x / 0 # knot: ignore[division-by-zero unresolved-reference] | ||
| ``` | ||
|
|
||
| ## Empty codes | ||
|
|
||
| An empty codes array suppresses no-diagnostics and is always useless | ||
|
|
||
| ```py | ||
| # error: [division-by-zero] | ||
| a = 4 / 0 # knot: ignore[] | ||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this something that we should flag, or just let it pass silently?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch. I updated #15084 to correctly mark the suppression as unused