Casting into to cpdef enum
See original GitHub issueSimplified code:
cpdef enum MyEnum:
MY_VAL=2
def my_fn():
return <MyEnum>2
I’d expect my_fn() to return MyEnum.MY_VAL, but just returns the int value.
Issue Analytics
- State:
- Created 5 years ago
- Comments:12 (8 by maintainers)
Top Results From Across the Web
How to access an enum type by value in cython - Stack Overflow
The problem I see with this technique is that you cannot convert from a string to the original enum class, and in the...
Read more >Language Basics — Cython 3.0.0a11 documentation
You need to assign a value at some point before first using the variable, ... Declaring an enum as cpdef will create a...
Read more >Wrapping strongly typed enums - Google Groups
How do I wrap strongly typed enums ("enum class") in Cython? In my file.hpp file I have an Algorithm enum as follows: enum...
Read more >[Cython] Problem with declaring a map with an enum type.
I have a C enum type that I'm attempting to put in a C++ map: Here's ... from libcpp.map cimport map cdef extern...
Read more >What is the reason for this Cython compile error when ...
I am working on a Raspberry PI using Python 3.4.2 with Cython 0.24 and GCC 4.9.1. I want to use a cpdef enum...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
(Not Stefan but) I have a 50% written change with the conversion code in as a
cdef __Pyx_Enum_{{name}}_to_py(int c_val)
inCpdefEnum.pyx
(and called from thePyrexTypes.CEnumType.create_to_py_utility_code
function).I’m not sure there’s a better way to approach this - Cython doesn’t look to have much special knowledge of the Python enum
yes
Thanks Stefan 🙏
Do you have a sense of where it would make sense to add conversion code like this?
Agree there is likely a better way to handle accessing the right
IntEnum
value. Do you have thoughts on what would be the best way to approach this?Also guessing we can do some templating to simplify the branch logic (if that is the right way to go).