Browse Source

Merge branch 'master' of github.com:micropython/micropython

pull/380/merge
Damien George 11 years ago
parent
commit
f61a072f68
  1. 7
      py/builtin.c
  2. 1
      py/builtin.h
  3. 1
      py/builtintables.c
  4. 1
      py/qstrdefs.h
  5. 15
      tests/basics/getattr1.py

7
py/builtin.c

@ -388,3 +388,10 @@ STATIC mp_obj_t mp_builtin_id(mp_obj_t o_in) {
}
MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_id_obj, mp_builtin_id);
STATIC mp_obj_t mp_builtin_getattr(mp_obj_t o_in, mp_obj_t attr) {
assert(MP_OBJ_IS_QSTR(attr));
return rt_load_attr(o_in, MP_OBJ_QSTR_VALUE(attr));
}
MP_DEFINE_CONST_FUN_OBJ_2(mp_builtin_getattr_obj, mp_builtin_getattr);

1
py/builtin.h

@ -12,6 +12,7 @@ MP_DECLARE_CONST_FUN_OBJ(mp_builtin_dir_obj);
MP_DECLARE_CONST_FUN_OBJ(mp_builtin_divmod_obj);
MP_DECLARE_CONST_FUN_OBJ(mp_builtin_eval_obj);
MP_DECLARE_CONST_FUN_OBJ(mp_builtin_exec_obj);
MP_DECLARE_CONST_FUN_OBJ(mp_builtin_getattr_obj);
MP_DECLARE_CONST_FUN_OBJ(mp_builtin_hash_obj);
MP_DECLARE_CONST_FUN_OBJ(mp_builtin_id_obj);
MP_DECLARE_CONST_FUN_OBJ(mp_builtin_isinstance_obj);

1
py/builtintables.c

@ -60,6 +60,7 @@ STATIC const mp_builtin_elem_t builtin_object_table[] = {
{ MP_QSTR_divmod, (mp_obj_t)&mp_builtin_divmod_obj },
{ MP_QSTR_eval, (mp_obj_t)&mp_builtin_eval_obj },
{ MP_QSTR_exec, (mp_obj_t)&mp_builtin_exec_obj },
{ MP_QSTR_getattr, (mp_obj_t)&mp_builtin_getattr_obj },
{ MP_QSTR_hash, (mp_obj_t)&mp_builtin_hash_obj },
{ MP_QSTR_id, (mp_obj_t)&mp_builtin_id_obj },
{ MP_QSTR_isinstance, (mp_obj_t)&mp_builtin_isinstance_obj },

1
py/qstrdefs.h

@ -92,6 +92,7 @@ Q(eval)
Q(exec)
Q(filter)
Q(float)
Q(getattr)
Q(hash)
Q(id)
Q(int)

15
tests/basics/getattr1.py

@ -0,0 +1,15 @@
class A:
var = 132
def __init__(self):
self.var2 = 34
def meth(self, i):
return 42 + i
a = A()
print(getattr(a, "var"))
print(getattr(a, "var2"))
print(getattr(a, "meth")(5))
Loading…
Cancel
Save