Keaton correctness

Is the code generated by Cython always as valid as the Python code from which it was created?

This may help other readers turn to using Cython static type declarations and other Cython functions (if any), although I'm only interested in creating Cython files by renaming Python modules to * .pyx.

I only care about the subset of Python covered by Cython.

+7
source share
1 answer

Generally yes. Of course, there are errors (many revolve around the extension of the supported subset of Python, although the errors that actually make the generated C code wrong are relatively rare), and there are several necessary caveats (although it seems that only one element in this short list is distracted from semantics Python).

When you add static types in pure Python mode, there are circumstances in which it matters whether it is compiled as Cython or executed as Python code. Fixed integers come to mind (for example: as mentioned in one link above, -n will wrap if unsigned n and range(-n, n) are therefore empty), as well as integer overflow (Python advances int (C long s) to long (integers of refractive accuracy)).

+10
source

All Articles