1# test handling of failed heap allocation with list
2
3import micropython
4
5
6class GetSlice:
7    def __getitem__(self, idx):
8        return idx
9
10
11sl = GetSlice()[:]
12
13# create slice in VM
14l = [1, 2, 3]
15micropython.heap_lock()
16try:
17    print(l[0:1])
18except MemoryError:
19    print("MemoryError: list index")
20micropython.heap_unlock()
21
22# get from list using slice
23micropython.heap_lock()
24try:
25    l[sl]
26except MemoryError:
27    print("MemoryError: list get slice")
28micropython.heap_unlock()
29
30# extend list using slice subscr
31l = [1, 2]
32l2 = [3, 4, 5, 6, 7, 8, 9, 10]
33micropython.heap_lock()
34try:
35    l[sl] = l2
36except MemoryError:
37    print("MemoryError: list extend slice")
38micropython.heap_unlock()
39print(l)
40