If I set language_level=2
in ext_modules = cythonize(extensions, language_level=2)
, what does that change? Is it just that the code I have written should be interpreted as Python2?
Is the end result exactly the same?
If I set language_level=2
in ext_modules = cythonize(extensions, language_level=2)
, what does that change? Is it just that the code I have written should be interpreted as Python2?
Is the end result exactly the same?
Building a cython extension is a two-step proccess:
foo.c
-file fromfoo.pyx
file using PythonX+cython-module.X
could be here 2.7, 3.7 or whatever version you prefer.Y
doesn't have to beX
, but in most casesY
andX
are the same.The resulting extension can be used with PythonY (it doesn't play a role what
X
was).However, there is still the question: In which Python-version was the original
pyx
-file written? Iflanguage_level
is not set, current Cython-versions assume that the pyx-file was written in the version2
(btw. this is not the case for IPython-%%cython-magic, where the version with which the filefoo.c
is cythonized).This behavior will change in the future, this is the reason you see the somewhat irritating warning, if you build with
cython>=0.29
:So you can explicitly set the
language_level
, so that your extension has the same behavior independent of the Python-version with which it was cythonized.For some examples of different behavior see, the follwoing example.
Using
language_level=3
:results in
but using
language_level=2
:results in
Obviously the above are only two examples, there are much more differences (e.g.
str
&unicode
stuff).