[Cython] cdef class tp_new should call PyBaseObject_Type.tp_new?

Simon Jagoe simon at simonjagoe.com
Wed Jan 8 21:17:08 CET 2014


Hi all,

I recently posted to the cython-users list about this problem. This
email is to submita potential patch to fix the issue. The issue is as
follows:


At Enthought we are busy porting Traits
(http://github.com/enthought/traits) from C to Cython.

An issue has come up that that prevents classes inheriting from a
cdef-class from playing nicely with ABCs.  It is type's tp_new that
checks for abstractmethods that have not been implemented, so if type's
tp_new is bypassed, the check is never run and you can instantiate an
abstract base class.

It is equivalent to this simple example below (taken from
http://stackoverflow.com/questions/20432335). If you replace the simple
class A with a Cython cdef class, the effect is the same.


import abc

class A(object):
    def __new__(cls):
        # self = object.__new__(cls)
        return 42

class B(A):
    __metaclass__ = abc.ABCMeta

    @abc.abstractmethod
    def foo(self):
        pass

b = B()  # No exception.


Thanks,
Simon
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-BUG-Call-PyBaseObject_Type.tp_new-instead-of-NewType.patch
Type: text/x-patch
Size: 989 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/cython-devel/attachments/20140108/bc7c5b12/attachment.bin>


More information about the cython-devel mailing list