-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[red-knot] Disallow more invalid type expressions
- Loading branch information
1 parent
cf83584
commit e1bb7b1
Showing
3 changed files
with
131 additions
and
40 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
crates/red_knot_python_semantic/resources/mdtest/annotations/invalid.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,45 @@ | ||
# Tests for invalid types in type expressions | ||
|
||
## Invalid types are rejected | ||
|
||
Many types are illegal in the context of a type expression: | ||
|
||
```py | ||
import typing | ||
from knot_extensions import AlwaysTruthy, AlwaysFalsy | ||
from typing_extensions import Literal, Never | ||
|
||
def _( | ||
a: type[int], | ||
b: AlwaysTruthy, | ||
c: AlwaysFalsy, | ||
d: Literal[True], | ||
e: Literal["bar"], | ||
f: Literal[b"foo"], | ||
g: tuple[int, str], | ||
h: Never, | ||
): | ||
def foo(): ... | ||
def invalid( | ||
i: a, # error: [invalid-type-form] "Variable of type `type[int]` is not allowed in a type expression" | ||
j: b, # error: [invalid-type-form] | ||
k: c, # error: [invalid-type-form] | ||
l: d, # error: [invalid-type-form] | ||
m: e, # error: [invalid-type-form] | ||
n: f, # error: [invalid-type-form] | ||
o: g, # error: [invalid-type-form] | ||
p: h, # error: [invalid-type-form] | ||
q: typing, # error: [invalid-type-form] | ||
r: foo, # error: [invalid-type-form] | ||
): | ||
reveal_type(i) # revealed: Unknown | ||
reveal_type(j) # revealed: Unknown | ||
reveal_type(k) # revealed: Unknown | ||
reveal_type(l) # revealed: Unknown | ||
reveal_type(m) # revealed: Unknown | ||
reveal_type(n) # revealed: Unknown | ||
reveal_type(o) # revealed: Unknown | ||
reveal_type(p) # revealed: Unknown | ||
reveal_type(q) # revealed: Unknown | ||
reveal_type(r) # revealed: Unknown | ||
``` |
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