mirror of
https://github.com/astral-sh/ruff
synced 2026-01-07 22:54:28 -05:00
[ty] Add code action to ignore diagnostic on the current line (#21595)
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user