Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

# cython: language_level=2 does not work as expected #2791

Closed
jdemeyer opened this issue Jan 9, 2019 · 2 comments · Fixed by #2792
Closed

# cython: language_level=2 does not work as expected #2791

jdemeyer opened this issue Jan 9, 2019 · 2 comments · Fixed by #2792

Comments

@jdemeyer
Copy link
Contributor

jdemeyer commented Jan 9, 2019

There seems to be a problem with handling # cython: language_level=2 when language_level=3str is set globally (for example, using the compiler_directives flag of cythonize()).

For some features like division, the Python 3 semantics are used anyway.

Example:

# cython: language_level=2
def test():
    ver = 3
    L = [ver for ver in [2]]
    print(f"effective language_level for list comprehension: {ver}")

    cdef object a = 3
    ver = int((a / 2) * 2)
    print(f"effective language_level for division: {ver}")

gives as output

>>> test()
effective language_level for list comprehension: 2
effective language_level for division: 3

Strangely enough, the opposite (# cython: language_level=3str when language_level=2 is set globally) works correctly.

@jdemeyer
Copy link
Contributor Author

jdemeyer commented Jan 9, 2019

The problems seems to be that set_language_level only adds future_directives but it never removes any.

@jdemeyer
Copy link
Contributor Author

jdemeyer commented Jan 9, 2019

PR coming...

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

Successfully merging a pull request may close this issue.

2 participants