mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-01 22:31:23 +00:00
[red-knot] Improve match
mdtests (#14951)
## Summary Minor improvement for the `match` tests to make sure we can't infer statically whether or not a certain `case` applies.
This commit is contained in:
parent
c1837e4189
commit
2ccc9b19a7
1 changed files with 25 additions and 22 deletions
|
@ -3,40 +3,43 @@
|
||||||
## With wildcard
|
## With wildcard
|
||||||
|
|
||||||
```py
|
```py
|
||||||
match 0:
|
def _(target: int):
|
||||||
case 1:
|
match target:
|
||||||
y = 2
|
case 1:
|
||||||
case _:
|
y = 2
|
||||||
y = 3
|
case _:
|
||||||
|
y = 3
|
||||||
|
|
||||||
reveal_type(y) # revealed: Literal[2, 3]
|
reveal_type(y) # revealed: Literal[2, 3]
|
||||||
```
|
```
|
||||||
|
|
||||||
## Without wildcard
|
## Without wildcard
|
||||||
|
|
||||||
```py
|
```py
|
||||||
match 0:
|
def _(target: int):
|
||||||
case 1:
|
match target:
|
||||||
y = 2
|
case 1:
|
||||||
case 2:
|
y = 2
|
||||||
y = 3
|
case 2:
|
||||||
|
y = 3
|
||||||
|
|
||||||
# revealed: Literal[2, 3]
|
# revealed: Literal[2, 3]
|
||||||
# error: [possibly-unresolved-reference]
|
# error: [possibly-unresolved-reference]
|
||||||
reveal_type(y)
|
reveal_type(y)
|
||||||
```
|
```
|
||||||
|
|
||||||
## Basic match
|
## Basic match
|
||||||
|
|
||||||
```py
|
```py
|
||||||
y = 1
|
def _(target: int):
|
||||||
y = 2
|
y = 1
|
||||||
|
y = 2
|
||||||
|
|
||||||
match 0:
|
match target:
|
||||||
case 1:
|
case 1:
|
||||||
y = 3
|
y = 3
|
||||||
case 2:
|
case 2:
|
||||||
y = 4
|
y = 4
|
||||||
|
|
||||||
reveal_type(y) # revealed: Literal[2, 3, 4]
|
reveal_type(y) # revealed: Literal[2, 3, 4]
|
||||||
```
|
```
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue