Skip to content

Commit 64a9d91

Browse files
committed
Add tests
1 parent 8906179 commit 64a9d91

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

tests/functional/p/potential_index_error.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,26 @@ def my_func():
2323
# Test that we don't crash on more complicated indices/slices
2424
# We do not raise here (currently)
2525
print([1, 2, 3][2:3])
26+
27+
28+
# Test for cases with unpacking operation
29+
my_list = ["foo", "bar"]
30+
my_set = {"foo", "bar"}
31+
my_tuple = ("foo", "bar")
32+
my_iterable = (*my_list, *my_set, *my_tuple, *("foo", "bar"))
33+
my_non_iterable = None
34+
35+
print([*my_list][1])
36+
print([*my_list][2]) # [potential-index-error]
37+
38+
print([*my_set][1])
39+
print([*my_set][2]) # [potential-index-error]
40+
41+
print((*my_tuple,)[1])
42+
print((*my_tuple,)[2]) # [potential-index-error]
43+
44+
print((*my_iterable,)[7])
45+
print((*my_iterable,)[8]) # [potential-index-error]
46+
47+
print((*my_non_iterable,)[0])
48+
print((*my_non_iterable,)[1]) # [potential-index-error]
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
potential-index-error:6:6:6:18::Invalid index for iterable length:INFERENCE
22
potential-index-error:7:6:7:18::Invalid index for iterable length:INFERENCE
33
potential-index-error:8:6:8:22::Invalid index for iterable length:INFERENCE
4+
potential-index-error:36:6:36:19::Invalid index for iterable length:INFERENCE
5+
potential-index-error:39:6:39:18::Invalid index for iterable length:INFERENCE
6+
potential-index-error:42:6:42:21::Invalid index for iterable length:INFERENCE
7+
potential-index-error:45:6:45:24::Invalid index for iterable length:INFERENCE
8+
potential-index-error:48:6:48:28::Invalid index for iterable length:INFERENCE

0 commit comments

Comments
 (0)