Skip to content

Commit

Permalink
Merge pull request #2063 from jtoledo1974/jtoledo1974/pure_python
Browse files Browse the repository at this point in the history
Added test case and fix for cython pure python import
  • Loading branch information
staticdev authored Dec 27, 2022
2 parents 98390f5 + 9b37e89 commit ff29175
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
5 changes: 4 additions & 1 deletion isort/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,10 @@ def process(
or " cimport " in import_statement
or " cimport*" in import_statement
or " cimport(" in import_statement
or ".cimport" in import_statement
or (
".cimport" in import_statement
and "cython.cimports" not in import_statement
) # Allow pure python imports. See #2062
):
cimport_statement = True

Expand Down
17 changes: 17 additions & 0 deletions tests/unit/test_ticketed_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -1056,3 +1056,20 @@ def test_sort_configurable_sort_issue_1732() -> None:
)
with pytest.raises(exceptions.SortingFunctionDoesNotExist):
isort.code(test_input, sort_order="round")


def test_cython_pure_python_imports_2062():
"""Test to ensure an import form a cython.cimports remains import, not cimport.
See: https://github.com/pycqa/isort/issues/2062.
"""
assert isort.check_code(
"""
import cython
from cython.cimports.libc import math
def use_libc_math():
return math.ceil(5.5)
""",
show_diff=True,
)

0 comments on commit ff29175

Please sign in to comment.