summaryrefslogtreecommitdiffstatshomepage
path: root/py
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2015-12-26 12:41:31 +0000
committerDamien George <damien.p.george@gmail.com>2015-12-26 12:41:31 +0000
commit78913211a9532ff952f5628c7c94848bd59a4a11 (patch)
treed0a87488951bcb98ff0958c2f384d5dde53cd848 /py
parent84b245f187f9711357b1fd46bebc67266bd028e5 (diff)
downloadmicropython-78913211a9532ff952f5628c7c94848bd59a4a11.tar.gz
micropython-78913211a9532ff952f5628c7c94848bd59a4a11.zip
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.
Diffstat (limited to 'py')
-rw-r--r--py/runtime.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/py/runtime.c b/py/runtime.c
index 3a1f588ab7..9ec282685f 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