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

Extra blank line always added before import heading #1290

Closed
rafikdraoui opened this issue Jul 6, 2020 · 1 comment
Closed

Extra blank line always added before import heading #1290

rafikdraoui opened this issue Jul 6, 2020 · 1 comment

Comments

@rafikdraoui
Copy link

When an import section that has a import_heading isn't at the module top-level, running isort on the file adds an extra new line before the heading comment every time, i.e. the transformation isn't idempotent.

config:

[settings]
known_special = special
import_heading_special = Special imports
sections=FUTURE,STDLIB,THIRDPARTY,SPECIAL,FIRSTPARTY,LOCALFOLDER

file:

from typing import TYPE_CHECKING

# Special imports
from special import thing

if TYPE_CHECKING:
    # Special imports
    from special import another_thing


def func():
    """Docstring"""

    # Special imports
    from special import something_else
    return

Running isort . gives the following diff:

diff --git a/f.py b/f.py
index f07d8ca..b71445c 100644
--- a/f.py
+++ b/f.py
@@ -4,6 +4,7 @@ from typing import TYPE_CHECKING
 from special import thing

 if TYPE_CHECKING:
+
     # Special imports
     from special import another_thing

@@ -11,6 +12,7 @@ if TYPE_CHECKING:
 def func():
     """Docstring"""

+
     # Special imports
     from special import something_else
     return

Running isort a second time modifies the file again, adding extra lines

diff --git a/f.py b/f.py
index b71445c..bc9d957 100644
--- a/f.py
+++ b/f.py
@@ -5,6 +5,7 @@ from special import thing

 if TYPE_CHECKING:

+
     # Special imports
     from special import another_thing

@@ -13,6 +14,7 @@ def func():
     """Docstring"""


+
     # Special imports
     from special import something_else
     return

And so on for further runs of isort.

@timothycrosley
Copy link
Member

Thank you for reporting this especially nasty issue! I'm sorry it impacted you!
I've fixed it in the just released 5.0.5 patch release, with additional regression testing in place to ensure it doesn't resurface.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants