[cython-users] struct has no member 'None' when accessing a list-derived type from a cdef function

27 views
Skip to first unread message

Saúl Ibarra Corretgé

unread,
May 27, 2011, 6:22:12 AM5/27/11
to cython...@googlegroups.com
Hi,

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

Robert Bradshaw

unread,
May 27, 2011, 7:37:39 PM5/27/11
to cython...@googlegroups.com

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

Saúl Ibarra Corretgé

unread,
May 30, 2011, 5:28:49 AM5/30/11
to cython...@googlegroups.com
Hi 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,

Robert Bradshaw

unread,
May 31, 2011, 12:35:18 AM5/31/11
to cython...@googlegroups.com
On Mon, May 30, 2011 at 2:28 AM, Saúl Ibarra Corretgé <sag...@gmail.com> wrote:
> Hi 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?

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

Reply all
Reply to author
Forward
0 new messages