@@ -42,6 +42,15 @@ To suppress multiple violations on a single line, enumerate each rule separated
4242sum_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
5261ty supports the standard [ ` type: ignore ` ] ( https://typing.python.org/en/latest/spec/directives.html#type-ignore-comments ) comment
5362format 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
6072sum_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