From 78913211a9532ff952f5628c7c94848bd59a4a11 Mon Sep 17 00:00:00 2001 From: Damien George Date: Sat, 26 Dec 2015 12:41:31 +0000 Subject: py: Be more restrictive binding self when looking up instance attrs. When looking up and extracting an attribute of an instance, some attributes must bind self as the first argument to make a working method call. Previously to this patch, any attribute that was callable had self bound as the first argument. But Python specs require the check to be more restrictive, and only functions, closures and generators should have self bound as the first argument Addresses issue #1675. --- py/runtime.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'py/runtime.c') diff --git a/py/runtime.c b/py/runtime.c index 3a1f588ab..9ec282685 100644 --- a/py/runtime.c +++ b/py/runtime.c @@ -947,7 +947,11 @@ void mp_convert_member_lookup(mp_obj_t self, const mp_obj_type_t *type, mp_obj_t } else if (MP_OBJ_IS_TYPE(member, &mp_type_type)) { // Don't try to bind types (even though they're callable) dest[0] = member; - } else if (mp_obj_is_callable(member)) { + } else if (MP_OBJ_IS_FUN(member) + || (MP_OBJ_IS_OBJ(member) + && (((mp_obj_base_t*)MP_OBJ_TO_PTR(member))->type->name == MP_QSTR_closure + || ((mp_obj_base_t*)MP_OBJ_TO_PTR(member))->type->name == MP_QSTR_generator))) { + // only functions, closures and generators objects can be bound to self #if MICROPY_BUILTIN_METHOD_CHECK_SELF_ARG if (self == MP_OBJ_NULL && mp_obj_get_type(member) == &mp_type_fun_builtin) { // we extracted a builtin method without a first argument, so we must -- cgit v1.2.3