diff options
author | Damien George <damien@micropython.org> | 2020-09-26 01:17:11 +1000 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2021-01-29 23:57:10 +1100 |
commit | 925bd67cfb1607264fae79a4fdf5e79ab1ae46aa (patch) | |
tree | 72b522d28b71467e8fced05449ae169484c47e91 /py/objfun.c | |
parent | 5d68b5e22ca361676903c68a5c004bdff40dd88b (diff) |
py/objfun: Support fun.__globals__ attribute.
This returns a reference to the globals dict associated with the function,
ie the global scope that the function was defined in. This attribute is
read-only but the dict itself is modifiable, per CPython behaviour.
Signed-off-by: Damien George <damien@micropython.org>
Diffstat (limited to 'py/objfun.c')
-rw-r--r-- | py/objfun.c | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/py/objfun.c b/py/objfun.c index 052f4b1ce..178f83443 100644 --- a/py/objfun.c +++ b/py/objfun.c @@ -355,6 +355,10 @@ void mp_obj_fun_bc_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { if (attr == MP_QSTR___name__) { dest[0] = MP_OBJ_NEW_QSTR(mp_obj_fun_get_name(self_in)); } + if (attr == MP_QSTR___globals__) { + mp_obj_fun_bc_t *self = MP_OBJ_TO_PTR(self_in); + dest[0] = MP_OBJ_FROM_PTR(self->globals); + } } #endif |