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

Added test case and fix for cython pure python import #2063

Merged
merged 2 commits into from
Dec 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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,
)