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

New line added if import is in function #1277

Closed
shardros opened this issue Jul 6, 2020 · 9 comments
Closed

New line added if import is in function #1277

shardros opened this issue Jul 6, 2020 · 9 comments
Labels
bug Something isn't working repo_needed Can't currently reproduce, if reproduction steps are added we will resivit this issue.

Comments

@shardros
Copy link

shardros commented Jul 6, 2020

Hello,

Firstly thank you for all your work on isort v5 is truely something.

I know this is a bit nasty to be doing anyway but if your imports are in a function with one line between them isort will always add a new line between them.

Before isort:

def main():
    import time

    import sys

After isort:

def main():
    import time


    import sys

After running isort a second time:

def main():
    import time



    import sys

Tested on commit: 686d3c7

@shardros
Copy link
Author

shardros commented Jul 7, 2020

The current work around which I am using is to run autopep8 after isort which cleans this up.

@timothycrosley
Copy link
Member

Hi @shardros,

Thanks for the positive feedback on the 5.0.0 release, it is really appreciated!

I'm sorry you are experiencing this issue, and I hope I can resolve it as quickly as possible. I haven't been able to reproduce it locally or on CI/CD, but I trust with some additional info I will be able to.

Could you

  • Try isort 5.0.5 and see if it still occurs for you? (there's a small chance this was fixed in develop before I added the test case)
  • Provide any settings used when running isort. A quick way to get this is to paste the result of isort --show-config
  • Provide the OS isort is being ran from?

Thanks!

~Timothy

@timothycrosley timothycrosley added bug Something isn't working repo_needed Can't currently reproduce, if reproduction steps are added we will resivit this issue. labels Jul 8, 2020
@ziima
Copy link

ziima commented Jul 9, 2020

I can't quite reproduce the issue, but I have a similar issue. Isort splits imports in functions in sections, which I don't really like.

Running

isort --check-only --diff test.py

on a file

def main():
    import sys
    from django import setup

produces

--- /tmp/test/test.py:before	2020-07-09 09:09:32.168479
+++ /tmp/test/test.py:after	2020-07-09 09:09:44.959117
@@ -1,3 +1,4 @@
 def main():
     import sys
+
     from django import setup

In my opinion, splitting the imports into sections inside functions is not that useful. I haven't found a setting which would help with that.

@shardros
Copy link
Author

shardros commented Jul 9, 2020

Hello @timothycrosley,

Thank you for your suggestions. Here is a repository with what I believe to be minimal code needed to reproduce the bug.

This was tested on windows. I don't have access to a Linux system to test this on right now but will try over the weekend. The output of isort --show-config and the exact OS is listed in the README.md of the repo.

Sadly isort 5.0.5 does not seem to solve the problem.

Thank you for all of your hard work,

Edwin

@shardros
Copy link
Author

shardros commented Jul 9, 2020

I am unable to reproduce @ziima 's issue in the virtual env in this repository which exhibits the original bug.

@ziima
Copy link

ziima commented Jul 10, 2020

You have constrained isort version to 5.0.5. There is already 5.0.7.

@sbrugman
Copy link

Thanks Timothy for your work on v5, much appreciated!

In case it might help locating the issue: we observe the same behaviour when running Windows and Ubuntu through the WSL. Isort works as expected on Github Actions running Ubuntu.

@timothycrosley
Copy link
Member

Thanks everyone for the detailed information on this issue! Based on the details I borrowed a windows machine and was able to reproduce the issue almost right away. This should be fixed in the just release 5.0.8 release, with an additional regression test added to ensure it doesn't reappear.

@shardros
Copy link
Author

Thank you @timothycrosley

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working repo_needed Can't currently reproduce, if reproduction steps are added we will resivit this issue.
Projects
None yet
Development

No branches or pull requests

4 participants