1# Check that yield-from can work without heap allocation 2 3import micropython 4 5# Yielding from a function generator 6def sub_gen(a): 7 for i in range(a): 8 yield i 9 10 11def gen(g): 12 yield from g 13 14 15g = gen(sub_gen(4)) 16micropython.heap_lock() 17print(next(g)) 18print(next(g)) 19micropython.heap_unlock() 20 21# Yielding from a user iterator 22class G: 23 def __init__(self): 24 self.value = 0 25 26 def __iter__(self): 27 return self 28 29 def __next__(self): 30 v = self.value 31 self.value += 1 32 return v 33 34 35g = gen(G()) 36micropython.heap_lock() 37print(next(g)) 38print(next(g)) 39micropython.heap_unlock() 40