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

Incorrectly turned an import into a cimport in a cython 3 pure python file #2062

Closed
jtoledo1974 opened this issue Dec 27, 2022 · 0 comments
Closed

Comments

@jtoledo1974
Copy link
Contributor

With the current version of cython it is possible to use valid python syntax to do what used to need a cimport statement.

So isort turns

import cython
from cython.cimports.libc import math


def use_libc_math():
    return math.ceil(5.5)

into

import cython

from cython.cimports.libc cimport math


def use_libc_math():
    return math.ceil(5.5)

The resulting file cannot be run by the python interpreter, breaks tests and breaks the cython compilation

(venv311) C:\Users\Juan\cruji-enaire>cython -a test.py
C:\Users\Juan\venv311\Lib\site-packages\Cython\Compiler\Main.py:345: FutureWarning: Cython directive 'language_level' not set, using '3str' for now (Py3). This has changed from earlier releases! File: C:\Users\Juan\cruji-enaire\test.py
  tree = Parsing.p_module(s, pxd, full_module_name)

Error compiling Cython file:
------------------------------------------------------------
...
import cython

from cython.cimports.libc cimport math
                          ^
------------------------------------------------------------

test.py:3:26: Expected 'import' or 'cimport'

isort should be able to recognize the new from cython.cimports syntax and don't turn the import into a cimport.

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

No branches or pull requests

1 participant