From e22b7fb4afbf62a9ca3162539c2d0236aefd8945 Mon Sep 17 00:00:00 2001 From: Damien George Date: Sat, 25 Jun 2022 00:05:39 +1000 Subject: py/objfun: Support function attributes on native functions. Native functions can just reuse the bytecode function attribute code. Signed-off-by: Damien George --- tests/micropython/native_fun_attrs.py | 25 +++++++++++++++++++++++++ tests/micropython/native_fun_attrs.py.exp | 4 ++++ 2 files changed, 29 insertions(+) create mode 100644 tests/micropython/native_fun_attrs.py create mode 100644 tests/micropython/native_fun_attrs.py.exp (limited to 'tests/micropython') diff --git a/tests/micropython/native_fun_attrs.py b/tests/micropython/native_fun_attrs.py new file mode 100644 index 000000000..e61c86975 --- /dev/null +++ b/tests/micropython/native_fun_attrs.py @@ -0,0 +1,25 @@ +# test native function attributes + + +def f(): + pass + + +if not hasattr(f, "__name__"): + print("SKIP") + raise SystemExit + + +@micropython.native +def native_f(): + pass + + +print(type(native_f.__name__)) +print(type(native_f.__globals__)) +print(native_f.__globals__ is globals()) + +try: + native_f.__name__ = None +except AttributeError: + print("AttributeError") diff --git a/tests/micropython/native_fun_attrs.py.exp b/tests/micropython/native_fun_attrs.py.exp new file mode 100644 index 000000000..8be35e2f6 --- /dev/null +++ b/tests/micropython/native_fun_attrs.py.exp @@ -0,0 +1,4 @@ + + +True +AttributeError -- cgit v1.2.3