circuitpython/tests/micropython/native_fun_attrs_code.py
Damien George ceb8ba60b4 py/objfun: Implement function.__code__ and function constructor.
This allows retrieving the code object of a function using
`function.__code__`, and then reconstructing a function from a code object
using `FunctionType(code_object)`.

This feature is controlled by `MICROPY_PY_FUNCTION_ATTRS_CODE` and is
enabled at the full-features level.

Signed-off-by: Damien George <damien@micropython.org>
2025-02-11 16:51:50 +11:00

21 lines
367 B
Python

# Test MicroPython-specific restrictions of function.__code__ attribute.
try:
(lambda: 0).__code__
except AttributeError:
print("SKIP")
raise SystemExit
import micropython
@micropython.native
def f_native():
pass
# Can't access __code__ when function is native code.
try:
f_native.__code__
except AttributeError:
print("AttributeError")