title: Have C extension class inherit from Python class
body: <p>I have a Python class <code>AbstractFoo</code> which uses <code>@abc.abstractmethod</code> to define 2 abstract methods.</p>
  
  <p>For more performance the bulk of the work is implemented in C as a Python extension class <code>CFoo</code>, so what I wanted to do is to inherit that extension class from <code>AbstractFoo</code>.</p>
  
  <p>However I haven't found a way to do this and went a different route: Implement it as a "normal" class in C and have a <code>class ConcreteFoo(AbstractFoo, CFoo)</code> which inherits from the abstract Python and the extension class.</p>
  
  <p>However now the "protection" from the ABC didn't kick in: No error was thrown even when the methods were missing. I found a solution in <a href="https://stackoverflow.com/a/20440259/1930508">https://stackoverflow.com/a/20440259/1930508</a> and added a new <code>new</code> method instead of <code>PyType_GenericNew</code> (ignore the ref counts of the empty_* parts for now):</p>
  
  <pre><code>static PyObject* CFoo_new(PyTypeObject* type, PyObject*, PyObject*)
  {
      auto* empty_tuple(PyTuple_New(0));
      if (!empty_tuple)
          return nullptr;
      auto* empty_dict(PyDict_New());
      if (!empty_dict)
          return nullptr;
      return PyBaseObject_Type.tp_new(type, empty_tuple.get(), empty_dict.get());
  }
  </code></pre>
  
  <p>But now the ABC check always triggers: <code>TypeError: Can't instantiate abstract class ConcreteFoo with abstract methods ...</code><br>
  But checking <code>dir(ConcreteFoo)</code> shows the methods it complains about.</p>
  
  <p>Is there a way to have an ABC-checked subclass of my <code>AbstractFoo</code> where the methods are implemented in C?</p>
  
  <p>Edit: Some more code:</p>
  
  <pre><code>class AbstractFoo(abc.ABC):
      @abc.abstractmethod
      def register(self):
          pass
      # ...
  
  #...
  
  class ConcreteFoo(AbstractFoo, CFoo):
      def __init__(self, arg):
          AbstractFoo.__init__(self)
          CFoo.__init__(self, arg)
  </code></pre>