Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions docs/suppression.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ To suppress multiple violations on a single line, enumerate each rule separated
sum_three_numbers("one", 5) # ty: ignore[missing-argument, invalid-argument-type]
```

To suppress specific rules for an entire file, place a `# ty: ignore[<rule>]` comment on its own
line before any Python code:

```python
# ty: ignore[invalid-argument-type]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it critical here that there's a blank line between this and any Python code? Like is this different than:

# ty: ignore[invalid-argument-type]
sum_three_numbers(3, 2, "1")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, as long as there is nothing before it, it's a file-wide suppression comment either way. And we don't support previous-line suppression comments.

I suspect this formatting is just to emphasize that it's not a previous-line suppression comment. It's a bit unfortunate how easily it could look like one, though in real code it's probably not an issue, since there will likely be new lines, an import block, etc.


sum_three_numbers(3, 2, "1")
```

!!! note

Enumerating rule names (e.g., `[rule1, rule2]`) is optional. However, we strongly recommend
Expand All @@ -52,12 +61,18 @@ sum_three_numbers("one", 5) # ty: ignore[missing-argument, invalid-argument-typ
ty supports the standard [`type: ignore`](https://typing.python.org/en/latest/spec/directives.html#type-ignore-comments) comment
format introduced by PEP 484.

ty handles these similarly to `ty: ignore` comments, but suppresses all violations on that line,
even when `type: ignore[code]` is used.
`type: ignore` suppresses all violations on that line.

`type: ignore[ty:<rule>]` behaves like `ty: ignore[<rule>]` and only suppresses the matching
rule. Codes without a `ty:` prefix are ignored, which makes it possible to combine
suppressions for multiple type checkers in a single comment.

```python
# Ignore all typing errors on the next line
sum_three_numbers("one", 5) # type: ignore

# Ignore a mypy code and a ty rule in the same comment
sum_three_numbers("one", 5, 2) # type: ignore[arg-type, ty:invalid-argument-type]
```

## Multiple suppressions comments
Expand Down