Skip to content

add_imports moves comments following import section #1300

@ziima

Description

@ziima

When using add_imports, isort moves comments following the import section to its beginning.

For example a command

isort --check-only --diff test.py --add-import 'from __future__ import unicode_literals'

applied to a file

from __future__ import unicode_literals

from os import path

# A comment for a constant
ANSWER = 42

results in

ERROR: /tmp/test/test.py Imports are incorrectly sorted and/or formatted.
--- /tmp/test/test.py:before	2020-07-08 13:28:31.901108
+++ /tmp/test/test.py:after	2020-07-08 13:32:21.272221
@@ -1,6 +1,6 @@
+# A comment for a constant
 from __future__ import unicode_literals
 
 from os import path
 
-# A comment for a constant
 ANSWER = 42

Affected version: 5.0.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions