File tree Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -326,7 +326,10 @@ def process(
326
326
or " cimport " in import_statement
327
327
or " cimport*" in import_statement
328
328
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
330
333
):
331
334
cimport_statement = True
332
335
Original file line number Diff line number Diff line change @@ -1056,3 +1056,20 @@ def test_sort_configurable_sort_issue_1732() -> None:
1056
1056
)
1057
1057
with pytest .raises (exceptions .SortingFunctionDoesNotExist ):
1058
1058
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
+ )
You can’t perform that action at this time.
0 commit comments