Ticket #776 (closed defect: invalid)

Opened 12 months ago

Last modified 11 months ago

Support extension type inheritance in pure python mode (@cclass)

Reported by: valmynd Owned by: somebody
Priority: major Milestone: 0.17
Component: Pure Python Mode Keywords:
Cc:

Description

The following doesn't work:

@cython.cclass
class BaseClass(object):
        attr = cython.declare(unicode)
        # ... (see attachement)
@cython.cclass
class Subclass(BaseClass):
        pass
print(core.Subclass().attr) # raises AttributeError: 'core.Subclass' object has no attribute 'attr'

I tried with cython 0.15 and trunc (github). I think a proper behaviour would be to let the @cython.cclass annotation do the same thing as if i would write "cdef class" in non-pure-py-mode, but I don't know much about the internals of how pure-python mode is handled.

Attachments

testcase1.zip Download (1.1 KB) - added by valmynd 12 months ago.
Simple Test Case
core.c Download (64.7 KB) - added by valmynd 12 months ago.
Generated C File

Change History

Changed 12 months ago by valmynd

Simple Test Case

Changed 12 months ago by valmynd

Generated C File

Changed 11 months ago by scoder

  • status changed from new to closed
  • resolution set to invalid

Works for me:

/* "t776.py":10
 * class Subclass(BaseClass):
 *         pass
 * print(Subclass().attr)                # <<<<<<<<<<<<<<
 */
  __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_4t776_Subclass)), ((PyObject *)__pyx_empty_tuple), NULL); if /*...*/
  __Pyx_GOTREF(__pyx_t_1);
  if (__Pyx_PrintOne(0, ((PyObject *)((struct __pyx_obj_4t776_Subclass *)__pyx_t_1)->__pyx_base.attr)) < 0) /*...*/

The problem is that Cython cannot know that "core.Subclass()" returns an instance of "Subclass". If you assign the object to a typed variable, it should work.

Note: See TracTickets for help on using tickets.