-
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] Porting to new structure after remarks
- Loading branch information
Showing
56 changed files
with
1,919 additions
and
2,027 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
crates/red_knot_python_semantic/resources/mdtest/assignment/annotations.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,25 @@ | ||
# Assignment with annotations | ||
|
||
## Annotation only transparent to local inference | ||
|
||
```py | ||
x = 1 | ||
x: int | ||
y = x | ||
|
||
reveal_type(y) # revealed: Literal[1] | ||
``` | ||
|
||
## Violates own annotation | ||
|
||
```py | ||
x: int = 'foo' # error: [invalid-assignment] "Object of type `Literal["foo"]` is not assignable to `int`" | ||
|
||
``` | ||
|
||
## Violates previous annotation | ||
|
||
```py | ||
x: int | ||
x = 'foo' # error: [invalid-assignment] "Object of type `Literal["foo"]` is not assignable to `int`" | ||
``` |
15 changes: 15 additions & 0 deletions
15
crates/red_knot_python_semantic/resources/mdtest/assignment/attributes.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,15 @@ | ||
# Class attributes assignment | ||
|
||
## Union of attributes | ||
|
||
```py | ||
if flag: | ||
class C: | ||
x = 1 | ||
else: | ||
class C: | ||
x = 2 | ||
|
||
y = C.x | ||
reveal_type(y) # revealed: Literal[1, 2] | ||
``` |
39 changes: 39 additions & 0 deletions
39
crates/red_knot_python_semantic/resources/mdtest/assignment/error_declaration.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,39 @@ | ||
# Errors while declaring | ||
|
||
## Violates previous assignment | ||
|
||
```py | ||
x = 1 | ||
x: str # error: [invalid-declaration] "Cannot declare type `str` for inferred type `Literal[1]`" | ||
``` | ||
|
||
## Incompatible declarations | ||
|
||
```py | ||
if flag: | ||
x: str | ||
else: | ||
x: int | ||
x = 1 # error: [conflicting-declarations] "Conflicting declared types for `x`: str, int" | ||
``` | ||
|
||
## Partial declarations | ||
|
||
```py | ||
if flag: | ||
x: int | ||
x = 1 # error: [conflicting-declarations] "Conflicting declared types for `x`: Unknown, int" | ||
``` | ||
|
||
## Incompatible declarations with bad assignment | ||
|
||
```py | ||
if flag: | ||
x: str | ||
else: | ||
x: int | ||
|
||
# error: [conflicting-declarations] | ||
# error: [invalid-assignment] | ||
x = b'foo' | ||
``` |
9 changes: 9 additions & 0 deletions
9
crates/red_knot_python_semantic/resources/mdtest/assignment/multi_target.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,9 @@ | ||
# Multi-target assignment | ||
|
||
## Basic | ||
|
||
```py | ||
x = y = 1 | ||
reveal_type(x) # revealed: Literal[1] | ||
reveal_type(y) # revealed: Literal[1] | ||
``` |
32 changes: 32 additions & 0 deletions
32
crates/red_knot_python_semantic/resources/mdtest/assignment/unbound.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,32 @@ | ||
# Unbound | ||
|
||
## Maybe unbound | ||
|
||
```py | ||
if flag: | ||
y = 3 | ||
x = y | ||
reveal_type(x) # revealed: Unbound | Literal[3] | ||
``` | ||
|
||
## Unbound | ||
|
||
```py | ||
x = foo; foo = 1 | ||
reveal_type(x) # revealed: Unbound | ||
``` | ||
|
||
## Unbound class variable | ||
|
||
Class variables can reference global variables unless overridden within the class scope. | ||
|
||
```py | ||
x = 1 | ||
class C: | ||
y = x | ||
if flag: | ||
x = 2 | ||
|
||
reveal_type(C.x) # revealed: Unbound | Literal[2] | ||
reveal_type(C.y) # revealed: Literal[1] | ||
``` |
17 changes: 17 additions & 0 deletions
17
crates/red_knot_python_semantic/resources/mdtest/assignment/walrus.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,17 @@ | ||
# Walrus operator | ||
|
||
## Basic | ||
|
||
```py | ||
x = (y := 1) + 1 | ||
reveal_type(x) # revealed: Literal[2] | ||
reveal_type(y) # revealed: Literal[1] | ||
``` | ||
|
||
## Walrus self-addition | ||
|
||
```py | ||
x = 0 | ||
(x := x + 1) | ||
reveal_type(x) # revealed: Literal[1] | ||
``` |
36 changes: 36 additions & 0 deletions
36
crates/red_knot_python_semantic/resources/mdtest/binary/integers.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,36 @@ | ||
## Binary operations on integers | ||
|
||
## Basic Arithmetic | ||
|
||
```py | ||
a = 2 + 1 | ||
b = a - 4 | ||
c = a * b | ||
d = c // 3 | ||
e = c / 3 | ||
f = 5 % 3 | ||
|
||
reveal_type(a) # revealed: Literal[3] | ||
reveal_type(b) # revealed: Literal[-1] | ||
reveal_type(c) # revealed: Literal[-3] | ||
reveal_type(d) # revealed: Literal[-1] | ||
reveal_type(e) # revealed: float | ||
reveal_type(f) # revealed: Literal[2] | ||
``` | ||
|
||
## Division by Zero | ||
|
||
```py | ||
# TODO: `a` should be `int` and `e` should be `float` once we support inference. | ||
a = 1 / 0 # error: "Cannot divide object of type `Literal[1]` by zero" | ||
b = 2 // 0 # error: "Cannot floor divide object of type `Literal[2]` by zero" | ||
c = 3 % 0 # error: "Cannot reduce object of type `Literal[3]` modulo zero" | ||
d = int() / 0 # error: "Cannot divide object of type `int` by zero" | ||
e = 1.0 / 0 # error: "Cannot divide object of type `float` by zero" | ||
|
||
reveal_type(a) # revealed: float | ||
reveal_type(b) # revealed: int | ||
reveal_type(c) # revealed: int | ||
reveal_type(d) # revealed: @Todo | ||
reveal_type(e) # revealed: @Todo | ||
``` |
Oops, something went wrong.