Skip to content

Compiler directive language_level is ignored if no Python statement is written before it. #2230

@rsaim

Description

@rsaim
$ cat temp.pyx
# cython: language_level=3
print("abc", "def", sep=" ,") # invalid in python 2

Compiling:

$ cythonize -i world_dep.pyx
Error compiling Cython file:
------------------------------------------------------------
...
# cython: language_level=3

print("abc", "def", sep=" ,")                      ^
------------------------------------------------------------
temp.pyx:4:23: Expected ')', found '='

So lanugage_level directive is not getting respected. Thus, cythonize ends up using Python 2 semantics and the error is thrown as the print statement above is invalid in Python 2.

However, including any Python statement before the print statement makes this work:

 $ cat temp.pyx
 # cython: language_level=3
 import os
 print("abc", "def", sep=" ,")
Compiling and executing:

$ cythonize -i temp.pyx; python -c "import temp"
abc, def

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions