Update documentation to reflect type:ignore changes (#3121)

## Summary

Update the documentation to reflect the changes introduced in
https://github.com/astral-sh/ruff/pull/24096
This commit is contained in:
Micha Reiser
2026-03-24 20:32:11 +00:00
committed by GitHub
parent 9e464322e6
commit db65b3e118
+17 -2
View File
@@ -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]
sum_three_numbers(3, 2, "1")
```
!!! note
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
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