From 6a17b30a34b231ef8567da7ecab2ea3b0db332b1 Mon Sep 17 00:00:00 2001 From: Raphael Gaschignard Date: Wed, 16 Oct 2024 10:26:02 +1000 Subject: [PATCH] Add list index stub tests --- .../mdtest/literal/collections/list.md | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/crates/red_knot_python_semantic/resources/mdtest/literal/collections/list.md b/crates/red_knot_python_semantic/resources/mdtest/literal/collections/list.md index 67b3e1f907b18..798f460f08a29 100644 --- a/crates/red_knot_python_semantic/resources/mdtest/literal/collections/list.md +++ b/crates/red_knot_python_semantic/resources/mdtest/literal/collections/list.md @@ -6,3 +6,35 @@ x = [] reveal_type(x) # revealed: list ``` + +## Indexing into lists + +A list can be indexed into with: + +- numbers +- slices + +```py +x = [1, 2, 3] +reveal_type(x) # revealed: list +# TODO reveal int +reveal_type(x[0]) # revealed: @Todo +# TODO reveal list +reveal_type(x[0:1]) # revealed: @Todo +# TODO error +reveal_type(x["a"]) # revealed: @Todo +``` + +## Assignments within list assignment + +In assignment, we might also have a named assignment. +This should also get type checked. + +```py +x = [1, 2, 3] +x[0 if (y := 2) else 1] = 5 +# TODO error? (indeterminite index type) +x["a" if (y := 2) else 1] = 6 +# TODO error (can't index via string) +x["a" if (y := 2) else "b"] = 6 +```