From 6e78e5462877ea62ec87a87a4aeeb6793650a354 Mon Sep 17 00:00:00 2001 From: Micha Reiser Date: Tue, 24 Mar 2026 10:07:53 +0100 Subject: [PATCH] Update documentation to reflect `type:ignore` changes --- docs/suppression.md | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/docs/suppression.md b/docs/suppression.md index 322b2f411..cbe9eaef5 100644 --- a/docs/suppression.md +++ b/docs/suppression.md @@ -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[]` 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:]` behaves like `ty: ignore[]` 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