circuitpython/tests/micropython/heapalloc_super.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

36 lines
571 B
Python
Raw Normal View History

# test super() operations which don't require allocation
import micropython
# Check for stackless build, which can't call functions without
# allocating a frame on heap.
try:
2021-03-15 09:57:36 -04:00
def stackless():
pass
micropython.heap_lock()
stackless()
micropython.heap_unlock()
except RuntimeError:
print("SKIP")
raise SystemExit
2021-03-15 09:57:36 -04:00
class A:
def foo(self):
2021-03-15 09:57:36 -04:00
print("A foo")
return 42
2021-03-15 09:57:36 -04:00
class B(A):
def foo(self):
2021-03-15 09:57:36 -04:00
print("B foo")
print(super().foo())
2021-03-15 09:57:36 -04:00
b = B()
micropython.heap_lock()
b.foo()
micropython.heap_unlock()