[ty] Add code action to ignore diagnostic on the current line (#21595)

This commit is contained in:
Micha Reiser
2025-11-29 15:41:54 +01:00
committed by GitHub
parent b2387f4eab
commit d40590c8f9
14 changed files with 868 additions and 32 deletions

View File

@@ -85,6 +85,50 @@ a = test \
+ 2 # type: ignore
```
## Interpolated strings
```toml
[environment]
python-version = "3.14"
```
Suppressions for expressions within interpolated strings can be placed after the interpolated string
if it's a single-line interpolation.
```py
a = f"""
{test}
""" # type: ignore
```
For multiline-interpolation, put the ignore comment on the expression's start or end line:
```py
a = f"""
{
10 / # type: ignore
0
}
"""
a = f"""
{
10 /
0 # type: ignore
}
"""
```
But not at the end of the f-string:
```py
a = f"""
{
10 / 0 # error: [division-by-zero]
}
""" # error: [unused-ignore-comment] # type: ignore
```
## Codes
Mypy supports `type: ignore[code]`. ty doesn't understand mypy's rule names. Therefore, ignore the