Skip to content

Commit ff29175

Browse files
authored
Merge pull request #2063 from jtoledo1974/jtoledo1974/pure_python
Added test case and fix for cython pure python import
2 parents 98390f5 + 9b37e89 commit ff29175

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

isort/core.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,10 @@ def process(
326326
or " cimport " in import_statement
327327
or " cimport*" in import_statement
328328
or " cimport(" in import_statement
329-
or ".cimport" in import_statement
329+
or (
330+
".cimport" in import_statement
331+
and "cython.cimports" not in import_statement
332+
) # Allow pure python imports. See #2062
330333
):
331334
cimport_statement = True
332335

tests/unit/test_ticketed_features.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,3 +1056,20 @@ def test_sort_configurable_sort_issue_1732() -> None:
10561056
)
10571057
with pytest.raises(exceptions.SortingFunctionDoesNotExist):
10581058
isort.code(test_input, sort_order="round")
1059+
1060+
1061+
def test_cython_pure_python_imports_2062():
1062+
"""Test to ensure an import form a cython.cimports remains import, not cimport.
1063+
See: https://github.com/pycqa/isort/issues/2062.
1064+
"""
1065+
assert isort.check_code(
1066+
"""
1067+
import cython
1068+
from cython.cimports.libc import math
1069+
1070+
1071+
def use_libc_math():
1072+
return math.ceil(5.5)
1073+
""",
1074+
show_diff=True,
1075+
)

0 commit comments

Comments
 (0)