-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8d32708
commit f0ce890
Showing
9 changed files
with
212 additions
and
41 deletions.
There are no files selected for viewing
94 changes: 94 additions & 0 deletions
94
crates/red_knot_python_semantic/resources/mdtest/suppressions/no-type-check.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
# `@no_type_check` | ||
|
||
> If a type checker supports the `no_type_check` decorator for functions, it should suppress all type errors for the def statement and its body including any nested functions or classes. It should also ignore all parameter and return type annotations and treat the function as if it were unannotated. | ||
> [source](https://typing.readthedocs.io/en/latest/spec/directives.html#no-type-check) | ||
## Error in the function body | ||
|
||
```py | ||
from typing import no_type_check | ||
|
||
@no_type_check | ||
def test() -> int: | ||
return a + 5 | ||
``` | ||
|
||
## Error in nested function | ||
|
||
```py | ||
from typing import no_type_check | ||
|
||
@no_type_check | ||
def test() -> int: | ||
def nested(): | ||
return a + 5 | ||
``` | ||
|
||
## Error in nested class | ||
|
||
```py | ||
from typing import no_type_check | ||
|
||
@no_type_check | ||
def test() -> int: | ||
class Nested: | ||
def inner(self): | ||
return a + 5 | ||
``` | ||
|
||
## Error in decorator | ||
|
||
Both MyPy and Pyright flag the `unknown_decorator` but we don't. | ||
|
||
```py | ||
from typing import no_type_check | ||
|
||
@unknown_decorator | ||
@no_type_check | ||
def test() -> int: | ||
return a + 5 | ||
``` | ||
|
||
## Error in default value | ||
|
||
```py | ||
from typing import no_type_check | ||
|
||
@no_type_check | ||
def test(a: int = "test"): | ||
return x + 5 | ||
``` | ||
|
||
## Error in return value position | ||
|
||
```py | ||
from typing import no_type_check | ||
|
||
@no_type_check | ||
def test() -> Undefined: | ||
return x + 5 | ||
``` | ||
|
||
## `no_type_check` on classes isn't supported | ||
|
||
Similar to Pyright, Red Knot does not support `no_type_check` annotations on classes. | ||
|
||
```py | ||
from typing import no_type_check | ||
|
||
@no_type_check | ||
class Test: | ||
def test(self): | ||
return a + 5 # error: [unresolved-reference] | ||
``` | ||
|
||
## `type: ignore` comments in `@no_type_check` blocks | ||
|
||
```py | ||
from typing import no_type_check | ||
|
||
@no_type_check | ||
def test(): | ||
# error: [unused-ignore-comment] | ||
return x + 5 # knot: ignore[unresolved-reference] | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.