Sorry if this has been posted already, I didn't quite know how to
phrase the problem, hence the weird title of this email.
In the following example (using Cython 0.14.1):
# ------------------------ #
cdef class MyList(list):
def foo(self):
print "foo"
cdef class Bar(object):
cdef MyList _attributes
def __init__(self, list attributes=None):
self.attributes = attributes if attributes is not None else []
property attributes:
def __get__(self):
return self._attributes
def __set__(self, list attributes not None):
self._attributes = attributes
cdef int _test(self):
self._attributes.append('foo')
# ------------------------ #
I'm getting th following error:
t.c: In function ‘__pyx_f_5hello_3Bar__test’:
t.c:1148:7: warning: comparison of distinct pointer types lacks a cast
t.c:1155:56: error: ‘struct __pyx_obj_5hello_MyList’ has no member named ‘None’
However, if I declare list as an explicit extern type:
cdef extern from "listobject.h":
ctypedef class __builtin__.list [object PyListObject]:
pass
It works. Am I doing something wrong here or is this a bug?
Kind regards,
--
/Saúl
http://saghul.net | http://sipdoc.net
This is a bug. However, note that the cython builtin "list" means
exactly a list (no subclasses allowed), otherwise we can't safely
optimize it (or, at least, we'd have to re-work our optimizations to
include dispatches to generic code, in which case there's little
benefit to typing it something other than "object."
- Robert
> This is a bug. However, note that the cython builtin "list" means
> exactly a list (no subclasses allowed), otherwise we can't safely
> optimize it (or, at least, we'd have to re-work our optimizations to
> include dispatches to generic code, in which case there's little
> benefit to typing it something other than "object."
>
Ok, thanks for the explanation! Is there a ticket created for this?
Regards,
I don't think so (short of the fact that I tagged this email as "bug"
to not forget it :), feel free to file one.
- Robert