Skip to content

Commit

Permalink
post-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaReiser committed Dec 24, 2024
1 parent 0f16ebd commit b08bece
Showing 1 changed file with 15 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
# `@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)
> 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:
def test() -> int:
return a + 5
```

Expand All @@ -20,7 +22,7 @@ from typing import no_type_check

@no_type_check
def test() -> int:
def nested():
def nested():
return a + 5
```

Expand Down Expand Up @@ -68,7 +70,7 @@ def test() -> int:
from typing import no_type_check

@no_type_check
def test(a: int = "test"):
def test(a: int = "test"):
return x + 5
```

Expand All @@ -78,17 +80,19 @@ def test(a: int = "test"):
from typing import no_type_check

@no_type_check
def test() -> Undefined:
def test() -> Undefined:
return x + 5
```

## `no_type_check` on classes isn't supported

Red Knot does not support `no_type_check` annotations on classes currently. The behaviour of
`no_type_check` when applied to classes is
[not fully specified currently](https://typing.readthedocs.io/en/latest/spec/directives.html#no-type-check),
and applying the decorator to classes is not supported by Pyright and possibly other type checkers.

Red Knot does not support `no_type_check` annotations on classes currently.
The behaviour of `no_type_check` when applied to classes is [not fully specified currently](https://typing.readthedocs.io/en/latest/spec/directives.html#no-type-check), and applying the decorator to classes is not supported by Pyright and possibly other type checkers.

A future improvement might be to emit a diagnostic if a `no_type_check` annotation is applied to a class.
A future improvement might be to emit a diagnostic if a `no_type_check` annotation is applied to a
class.

```py
from typing import no_type_check
Expand All @@ -108,4 +112,4 @@ from typing import no_type_check
def test():
# error: [unused-ignore-comment]
return x + 5 # knot: ignore[unresolved-reference]
```
```

0 comments on commit b08bece

Please sign in to comment.