1) don't cdef class attributes, it just makes debugging unnecessary hard. Unless you are wrapping C-level types where you can't avoid it, of course. Just keep it in python, maybe use cpdef if you must.
2) I'd recommend using __cinit__ instead of __init__ with cdef classes and use more of a RAII-style design. The cython ctor is always is called, the python ctor not necessarily! You are calling lazy_list_abstract.__new__ a couple of times and not manually initializing self.name, this is where your None (NULL in C) string attributes come from. On Sunday, January 10, 2016 at 12:16:24 PM UTC+1, Daniel Krenn wrote: > > I am trying to rewrite some code and have troubles with the following > code: > > cdef str s = self.name > if s: > s += ' ' > s += self.opening_delimiter > cdef list E = list('{!r}'.format(self.get(n)) > for n in xrange(min(num_elts, self.preview))) > if num_elts >= self.preview: > # PROBLEM/BUG with the following code line > # (run doctests of this file to see) > E.append(self.more) # <<<<<<<<<<<<<<< here > s += self.separator.join(E) > s += self.closing_delimiter > return s > > With the marked line, many doctests fail; like this: > > Failed example: > m2 > Expected: > lazy list [8, 10, 12, ...] > Got: > <repr(<sage.data_structures.lazy_list.lazy_list_abstract at > 0x7f684d746d40>) failed: TypeError: unsupported operand type(s) for +=: > 'NoneType' and 'NoneType'> > > Any ideas what goes wrong? (I've debugged now for over one hour and have > no glue (but I am no Cython expert)). > I've also tried without the "cdef str" and "cdef list" above. The > strings self.* are defined in the corresponding .pxd > > A branch with the code is on trac: u/dkrenn/cython-str-problem-append > file sage/data_structures/lazy_list.pyx, method __repr__, line 502 > > Best Daniel > -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at https://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.