Cython 0.29 broke support for C++ enum classes
See original GitHub issueBefore https://github.com/cython/cython/commit/be4ca1d685e8d703f2285183147f8587da56fe6d (a fix for #2186), on this input:
cpdef enum E "E":
A
Cython was generating this:
/* CIntToPy */
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_enum__E(enum E value) {
const enum E neg_one = (enum E) -1, const_zero = (enum E) 0;
Since https://github.com/cython/cython/commit/6079a5b0b0936feb2ec339a1f31d7d708ae6d3a3 it is generating this:
/* CIntToPy */
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_enum__E(enum E value) {
const enum E neg_one = (enum E) ((enum E) 0 - (enum E) 1), const_zero = (enum E) 0;
This works for C enums, but fails to compile for C++ enum classes (https://godbolt.org/z/NY8PJT):
enum class E { X };
const enum E neg_one_class_28 = (enum E) -1;
const enum E neg_one_class_29 = (enum E) ((enum E) 0 - (enum E) 1);
<source>:3:54: error: invalid operands to binary expression ('enum E' and 'enum E')
const enum E neg_one_class_29 = (enum E) ((enum E) 0 - (enum E) 1);
~~~~~~~~~~ ^ ~~~~~~~~~~
Issue Analytics
- State:
- Created 5 years ago
- Comments:10 (8 by maintainers)
Top Results From Across the Web
defines as nameless enum in Cython (nested in struct)
I have the following code from a C header: typedef struct { /* struct description */ int type; /* variable purpose: */ #define...
Read more >Cython Changelog — Cython 3.0.0a11 documentation
Improve compatibility between classes pickled in Cython 3.0 and 0.29.x by accepting MD5, ... C++17 execution policies are supported in libcpp.algorithm .
Read more >Declare global variables and class attributes in pure ...
I'm using cython 0.29.12 and python 3.7.0. Also to resolve my issue with global variable, I try these different approaches without success:.
Read more >Supported Python features
class definition: class (except for @jitclass); set, dict and generator comprehensions; generator delegation: yield from. Functions¶. Function calls ...
Read more >Release Notes — NumPy v1.17 Manual
Downstream developers should use Cython >= 0.29.13 for Python 3.8 support and ... are very rare in practice and only available through the...
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
They are not fully supported: for example, it seems difficult to use enum class variables as function arguments; but what Cython already has is enough to wrap them. The original example in #1603 can be encoded like this:
https://github.com/cython/cython/pull/3803 fixes this (tested locally).