From 9511f60f016547ab00f634d451c230351bd8b225 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sun, 11 May 2014 03:12:36 +0300 Subject: py: Don't try to "bind" types store as attributes of objects. This was hit when trying to make urlparse.py from stdlib run. Took quite some time to debug. TODO: Reconsile bound method creation process better, maybe callable is to generic type to bind at all? --- py/objtype.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'py/objtype.c') diff --git a/py/objtype.c b/py/objtype.c index 345eee714..ef5f6b9d9 100644 --- a/py/objtype.c +++ b/py/objtype.c @@ -333,6 +333,9 @@ STATIC void instance_convert_return_attr(mp_obj_t self, mp_obj_t member, mp_obj_ // return a bound method, with self being the type of this object dest[0] = ((mp_obj_static_class_method_t*)member)->fun; dest[1] = mp_obj_get_type(self); + } else if (MP_OBJ_IS_TYPE(member, &mp_type_type)) { + // Don't try to bind types + dest[0] = member; } else if (mp_obj_is_callable(member)) { // return a bound method, with self being this object dest[0] = member; -- cgit v1.2.3 From ea9708092e8a49377a465ef8c8500943fe9ba772 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sun, 11 May 2014 03:16:04 +0300 Subject: objtuple: Go out of the way to support comparison of subclasses. Two things are handled here: allow to compare native subtypes of tuple, e.g. namedtuple (TODO: should compare type too, currently compared duck-typedly by content). Secondly, allow user sunclasses of tuples (and its subtypes) be compared either. "Magic" I did previously in objtype.c covers only one argument (lhs is many), so we're in trouble when lhs is native type - there's no other option besides handling rhs in special manner. Fortunately, this patch outlines approach with fast path for native types. --- py/objtype.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'py/objtype.c') diff --git a/py/objtype.c b/py/objtype.c index ef5f6b9d9..c579477db 100644 --- a/py/objtype.c +++ b/py/objtype.c @@ -845,6 +845,15 @@ STATIC mp_obj_t mp_builtin_isinstance(mp_obj_t object, mp_obj_t classinfo) { MP_DEFINE_CONST_FUN_OBJ_2(mp_builtin_isinstance_obj, mp_builtin_isinstance); +mp_obj_t mp_instance_cast_to_native_base(mp_const_obj_t self_in, mp_const_obj_t native_type) { + mp_obj_type_t *self_type = mp_obj_get_type(self_in); + if (!mp_obj_is_subclass_fast(self_type, native_type)) { + return MP_OBJ_NULL; + } + mp_obj_instance_t *self = (mp_obj_instance_t*)self_in; + return self->subobj[0]; +} + /******************************************************************************/ // staticmethod and classmethod types (probably should go in a different file) -- cgit v1.2.3