Using C++ enum class in Python dict

512 views
Skip to first unread message

Eduardo Ponce

unread,
Sep 15, 2021, 2:15:22 AM9/15/21
to cython-users

Hi,

I am able to take a C++ unscoped enum defined in .pxd as cdef enum UnscopedEnum and use it as dictionary values in a .pyx file. Nevertheless, this does not seems to work for C++ scoped enums. I define it as ctypedef enum ScopedEnum but Cython triggers an error because it can't operate between ScopedEnum objects and integers.

Is there a simple workaround without having to create a helper class that explicitly casts the scoped enum to integers?

Thanks in advance,
~Eduardo

D Woods

unread,
Sep 17, 2021, 6:08:27 PM9/17/21
to cython-users

Scoped enums are explicitly supported in the Cython 3 alpha:

For earlier versions of Cython the workaround involved manually setting the names for the generated code in "strings" - see https://stackoverflow.com/questions/31001918/wrap-enum-class-with-cython

da-woods

unread,
Sep 17, 2021, 6:11:46 PM9/17/21
to cython...@googlegroups.com
Scoped enums are explicitly supported in the Cython 3 alpha:

For earlier versions of Cython the workaround involved manually setting the names for the generated code in "strings" - see https://stackoverflow.com/questions/31001918/wrap-enum-class-with-cython


--

---
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 on the web visit https://groups.google.com/d/msgid/cython-users/2354f024-0603-4fc8-9ae5-1a1211369746n%40googlegroups.com.


Eduardo Ponce

unread,
Sep 20, 2021, 1:05:19 AM9/20/21
to cython-users
Thanks for the prompt response!
You clarified my question for handling scoped enums.

~Eduardo
Reply all
Reply to author
Forward
0 new messages