Skip to content

Commit db65b3e

Browse files
authored
Update documentation to reflect type:ignore changes (#3121)
## Summary Update the documentation to reflect the changes introduced in astral-sh/ruff#24096
1 parent 9e46432 commit db65b3e

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

docs/suppression.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@ To suppress multiple violations on a single line, enumerate each rule separated
4242
sum_three_numbers("one", 5) # ty: ignore[missing-argument, invalid-argument-type]
4343
```
4444

45+
To suppress specific rules for an entire file, place a `# ty: ignore[<rule>]` comment on its own
46+
line before any Python code:
47+
48+
```python
49+
# ty: ignore[invalid-argument-type]
50+
51+
sum_three_numbers(3, 2, "1")
52+
```
53+
4554
!!! note
4655

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

55-
ty handles these similarly to `ty: ignore` comments, but suppresses all violations on that line,
56-
even when `type: ignore[code]` is used.
64+
`type: ignore` suppresses all violations on that line.
65+
66+
`type: ignore[ty:<rule>]` behaves like `ty: ignore[<rule>]` and only suppresses the matching
67+
rule. Codes without a `ty:` prefix are ignored, which makes it possible to combine
68+
suppressions for multiple type checkers in a single comment.
5769

5870
```python
5971
# Ignore all typing errors on the next line
6072
sum_three_numbers("one", 5) # type: ignore
73+
74+
# Ignore a mypy code and a ty rule in the same comment
75+
sum_three_numbers("one", 5, 2) # type: ignore[arg-type, ty:invalid-argument-type]
6176
```
6277

6378
## Multiple suppressions comments

0 commit comments

Comments
 (0)