Is there any documentation for implementing non-extern cppclass?

20 views
Skip to first unread message

Tapan Hazarika

unread,
Jun 26, 2026, 10:57:43 PM (6 days ago) Jun 26
to cython-users

I've been experimenting with a non-extern cppclass and found behavior that I couldn't find documented anywhere.

For example:

cdef cppclass Xyz:
    int x
    Xyz() nogil:
        this.x = 42
    void __dealloc__():
        pass

generates (simplified):

struct Xyz {
     int x; void __pyx_f___init__Xyz();
    void __pyx_f___dealloc__Xyz();
   Xyz() { __pyx_f___init__Xyz(); }
   ~Xyz() { __pyx_f___dealloc__Xyz(); }
};
void Xyz::__pyx_f___init__Xyz() { this->x = 42; }

I couldn't able to find any documentation describing what is supported. 

da-woods

unread,
Jun 27, 2026, 3:52:41 AM (6 days ago) Jun 27
to cython...@googlegroups.com

I think you're right and it isn't documented anywhere.

To me it's always seemed like a feature that probably shouldn't have been part of Cython. Mostly because it will always be fairly limited compared to just writing the C++ classes, so I don't think it's possible to get something that everyone's happy with without re-implementing C++ completely.  So I think the history was that it was added as an experimental feature and never documented. I don't think there's any chance of it being removed now, but personally I don't think the documentation should enthusiastically promote the feature.

If you look in tests/run/cpp_classes_def.pyx in the Cython repo, you can see a bunch of examples - that's probably the best I can recommend.

David

--

---
You received this message because you are subscribed to the Google Groups "cython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cython-users...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/cython-users/65d366d0-5b39-438a-a91e-7da4bca481cbn%40googlegroups.com.

Tapan Hazarika

unread,
Jun 27, 2026, 11:43:16 AM (6 days ago) Jun 27
to cython-users

Thanks!

That clears it up. It's also great to hear that it won't be removed. I'll definitely take a look at tests/run/cpp_classes_def.pyx.

Thanks again!

Reply all
Reply to author
Forward
0 new messages