Skip to content

Latest commit

 

History

History
120 lines (82 loc) · 2.35 KB

File metadata and controls

120 lines (82 loc) · 2.35 KB

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

a = 4 + test  # knot: ignore

Suppressing a specific code

a = 4 + test  # knot: ignore[unresolved-reference]

Useless suppression

TODO: Red Knot should emit an unused-suppression diagnostic for the possibly-unresolved-reference suppression.

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.

# error: [unresolved-reference]
a = test + 3  # knot: ignore[possibly-unresolved-reference]

Multiple suppressions

# 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

# error: [invalid-syntax]
def test(  # knot: ignore

Can't suppress revealed-type diagnostics

a = 10
# revealed: Literal[10]
reveal_type(a)  # knot: ignore

Extra whitespace in type ignore comments is allowed

a = 10 / 0  # knot   :   ignore
a = 10 / 0  # knot: ignore  [    division-by-zero   ]

Whitespace is optional

# fmt: off
a = 10 / 0  #knot:ignore[division-by-zero]

Trailing codes comma

Trailing commas in the codes section are allowed:

a = 10 / 0  # knot: ignore[division-by-zero,]

Invalid characters in codes

# error: [division-by-zero]
a = 10 / 0  # knot: ignore[*-*]

Trailing whitespace

a = 10 / 0  # knot: ignore[division-by-zero]      
            #                               ^^^^^^ trailing whitespace

Missing comma

A missing comma results in an invalid suppression comment. We may want to recover from this in the future.

# 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

# error: [division-by-zero]
a = 4 / 0  # knot: ignore[]