Support file-level type: ignore comments (#15081)

This commit is contained in:
Micha Reiser
2024-12-23 10:59:04 +01:00
committed by GitHub
parent 2f85749fa0
commit 1c3d11e8a8
3 changed files with 187 additions and 69 deletions

View File

@@ -118,3 +118,15 @@ An empty codes array suppresses no-diagnostics and is always useless
# error: [division-by-zero]
a = 4 / 0 # knot: ignore[]
```
## File-level suppression comments
File level suppression comments are currently intentionally unsupported because we've yet to decide
if they should use a different syntax that also supports enabling rules or changing the rule's
severity: `knot: possibly-undefined-reference=error`
```py
# knot: ignore[division-by-zero]
a = 4 / 0 # error: [division-by-zero]
```

View File

@@ -122,3 +122,36 @@ a = ( # type: ignore
test + 4 # error: [unresolved-reference]
)
```
## File level suppression
```py
# type: ignore
a = 10 / 0
b = a / 0
```
## File level suppression with leading shebang
```py
#!/usr/bin/env/python
# type: ignore
a = 10 / 0
b = a / 0
```
## Invalid own-line suppression
```py
"""
File level suppressions must come before any non-trivia token,
including module docstrings.
"""
# type: ignore
a = 10 / 0 # error: [division-by-zero]
b = a / 0 # error: [division-by-zero]
```