Skip to content

Instantly share code, notes, and snippets.

@tusharpm
Last active October 7, 2017 13:48
Show Gist options
  • Save tusharpm/ac0eef89796ca9c67ca92fe6c6071f6b to your computer and use it in GitHub Desktop.
Save tusharpm/ac0eef89796ca9c67ca92fe6c6071f6b to your computer and use it in GitHub Desktop.
Cython raw string literal broken example
from Cython.Compiler import Options
Options.annotate = True
Options.fast_fail = True
from Cython.Build import cythonize
cythonize(["main.pyx"], language='c++')
from mypxd cimport (
myInt
)
print(myInt)
# This one works.
# cdef extern from ".\\util.h":
# This one doesn't.
cdef extern from r".\util.h":
const unsigned myInt
const unsigned myInt = 32768;
@tusharpm
Copy link
Author

tusharpm commented Oct 4, 2017

This fails for the command: python cythonize.py
[where python is python.exe from python36 install directory]

But works for the equivalent command: cython -a --cplus -3 --fast-fail main.pyx
[where cython is cython.exe from python36 scripts directory]

@scoder
Copy link

scoder commented Oct 7, 2017

The two commands are actually not equivalent because you are not enabling Py3 mode in the first. Shouldn't make a difference here, though...

@tusharpm
Copy link
Author

tusharpm commented Oct 7, 2017

Nice catch. That was the problem.
Adding #cython: language_level=3 to the pxd file solved it.
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment