Skip to content

isort --atomic fails on Cython "cimport" syntax #1722

@DanielFEvans

Description

@DanielFEvans

isort --atomic fails for any Cython .pyx file containing a cimport statement, claiming it has an existing syntax error. A minimal example is:

cimport numpy
cimport ctime

isort buggy.pyx --diff runs fine:

$ isort buggy.pyx --diff
--- .../buggy.pyx:before       2021-05-06 10:19:09.495635
+++ .../buggy.pyx:after        2021-05-06 10:19:19.479452
@@ -1,2 +1,2 @@
+cimport ctime
 cimport numpy
-cimport ctime
Fixing .../buggy.pyx

However, isort buggy.pyx --diff --atomic fails:

$ isort buggy.pyx --diff --atomic
.../lib/python3.6/site-packages/isort/api.py:306: UserWarning: {file_path} unable to sort due to existing syntax errors

Bug found on isort v5.8.0, but the bug exists as far back as isort v5.0.0, when Cython support was added.

I presume the same issue will occur for any other Cython-specific syntax, too.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions