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 lines after imports are removed #219

Closed
ghost opened this issue Aug 28, 2022 · 2 comments · Fixed by #230
Closed

Extra blank lines after imports are removed #219

ghost opened this issue Aug 28, 2022 · 2 comments · Fixed by #230
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@ghost
Copy link

ghost commented Aug 28, 2022

Description

autoimport removes extra blank lines after imports, even when it’s required for PEP 8 compliance (e.g. when imports are directly followed by a class or a def). And also I like doing lines_after_imports = 2 in isort for consistency anyway.

While you may say I can just run another auto-formatter afterwards to fix the issue, this actually makes it impossible to use autoimport as a pre-commit hook, as on the next run autoimport will remove the blank line again, and pre-commit requires all hooks to succeed.

Steps to reproduce

  1. Create a file with the following contents:
     import random
    
    
     def foo():
         print(random.random())
  2. Run autoimport foo.py

Current behavior

The file gets rewritten to this:

    import random

    def foo():
        print(random.random())

Desired behavior

The file should remain untouched.

Environment

           autoimport version: 1.2.2
               python version: 3.10.4 (main, Apr  4 2022, 14:54:08) [GCC 10.2.1 20210110]
                     platform: Linux-5.10.0-16-amd64-x86_64-with-glibc2.31
@ghost ghost added the bug Something isn't working label Aug 28, 2022
@lyz-code
Copy link
Owner

Hi @nyuszika7h thanks for taking the time to open the issue. I see your point and agree it should be fixed.

Sadly I don't have time to implement this on my own, but if anyone is interested in contributing I think the easier way to do it is by implementing some logic when the different parts of the code are joined so that if the self.code starts with def or class it should add a new \n

@lyz-code lyz-code added the help wanted Extra attention is needed label Aug 29, 2022
lyz-code added a commit that referenced this issue Oct 14, 2022
lyz-code added a commit that referenced this issue Oct 14, 2022
lyz-code added a commit that referenced this issue Oct 14, 2022
@lyz-code
Copy link
Owner

Available since 1.3.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant