-
-
Notifications
You must be signed in to change notification settings - Fork 587
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
isort is (incorrectly) formatting code outside of imports #2315
Comments
Stumbled across this issue and I think I can at least unravel this mystery. I think this happens because "alembic" resolves to both the package as well as the folder it generates when you initialise it. I guess isort sees that "alembic" resolves to a local directory and places it with the other first party imports. |
Thanks for the reply and that makes a lot of sense. However, the much bigger issue is that isort is completely messing up the formatting of the blank lines. |
I not sure is it related or fully separate issue, but pre-commit.com hook with - repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort
name: isort
args: [--force-single-line, --profile=black] in next code, previously formatted by def test_subcommand_modules(mocker):
from pre_commit_terraform._cli_subcommands import (
SUBCOMMAND_MODULES as patched_subcommand_modules,
) replace indentation level from 4 spaces to 2: from pre_commit_terraform._cli_subcommands import (
- SUBCOMMAND_MODULES as patched_subcommand_modules,
+ SUBCOMMAND_MODULES as patched_subcommand_modules,
) Similar happens with def test_subcommand_modules(mocker):
- from pre_commit_terraform._cli_subcommands import (
- SUBCOMMAND_MODULES as patched_subcommand_modules,
- )
+ from pre_commit_terraform._cli_subcommands import \
+ SUBCOMMAND_MODULES as patched_subcommand_modules |
To be fair, having imports in function is a bad idea regardless of whether a formatter would get it or not… |
Given this snippet of code in my
alembic/env.py
file:After running
isort
, it produces this output:It mostly organizes the imports correctly (although I'm not sure why sqlalchemy is 3rd party and alembic is 1st party), but it removes several desired and PEP compliant blank lines outside of the import section.
I am using isort 5.13.2 with the following configuration options set in my
pyproject.toml
The text was updated successfully, but these errors were encountered: