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

Bug: Isort dropping # noqa comment #1594

Closed
Pacu2 opened this issue Nov 10, 2020 · 6 comments
Closed

Bug: Isort dropping # noqa comment #1594

Pacu2 opened this issue Nov 10, 2020 · 6 comments
Assignees
Labels
bug Something isn't working

Comments

@Pacu2
Copy link

Pacu2 commented Nov 10, 2020

Version: 5.6.4
Python 3.7
Description
Isort drops # noqa comment while sorting, when two imports from the same file/module exists, and one of them exceeds the max line length.

Steps to reproduce
Create two files with content as below. Sort test_isort.py with isort

test.py

class TestTestTestTestTestTest1:
    pass

class TestTestTestTestTestTest2:
    pass

class TestTestTestTestTestTest3:
    pass

class TestTestTestTestTestTest4:
    pass

class TestTestTestTestTestTest5:
    pass

test_isort.py

from .test import TestTestTestTestTestTest1  # noqa: F401
from .test import TestTestTestTestTestTest2, TestTestTestTestTestTest3, TestTestTestTestTestTest4, TestTestTestTestTestTest5  # noqa: F401

Actual result:

from .test import TestTestTestTestTestTest1  # noqa: F401; noqa: F401
from .test import (TestTestTestTestTestTest2, TestTestTestTestTestTest3,
                   TestTestTestTestTestTest4, TestTestTestTestTestTest5)

As you can see, #noqa comment was dropped from the second line, resulting in linter failling.

Expected result:
Imports should be joined together, single # noqa comment exists.

@timothycrosley timothycrosley added the bug Something isn't working label Nov 11, 2020
@anirudnits anirudnits self-assigned this Dec 9, 2020
@anirudnits
Copy link
Collaborator

Just to be clear, the expected result would look like

from .test import (TestTestTestTestTest1, ... # noqa: F401
                   ...,
                   TestTestTestTestTest5) 

@Pacu2
Copy link
Author

Pacu2 commented Dec 9, 2020

@anirudnits That's right, thanks

@Borda
Copy link

Borda commented Jan 19, 2021

That seems to be a dead lock with flake8 as PEP8 complains about unused imports and isort moves it...
just for the record, this is our config:

[isort]
line_length = 120
order_by_type = False
multi_line_output = 3
include_trailing_comma = True
honor_noqa = True

this is the input and also expected output:

from pl_bolts.models.self_supervised.moco.transforms import Moco2EvalCIFAR10Transforms  # noqa: F401
from pl_bolts.models.self_supervised.moco.transforms import (  # noqa: F401
    Moco2EvalImagenetTransforms,
    Moco2EvalSTL10Transforms,
   ...
)

and this is the result:

from pl_bolts.models.self_supervised.moco.transforms import Moco2EvalCIFAR10Transforms  # noqa: F401; noqa: F401
from pl_bolts.models.self_supervised.moco.transforms import (
    Moco2EvalImagenetTransforms,
    Moco2EvalSTL10Transforms,
   ...
)

just using isort==5.7.0
@anirudnits are you working on a fix? 🐰

@timothycrosley
Copy link
Member

timothycrosley commented Jan 20, 2021

@Borda,

Sorry to hear you are experiencing this issue as well! As a friendly reminder, in case you or others in this thread are unaware, while the project certainly prioritizes fixing issues like this, you should never feel stuck! isort provides many escape hatches for any disagreements with other tools, of particular good use for this issue is isort: off and isort: on action comments as detailed in the documentation here:

https://pycqa.github.io/isort/docs/configuration/action_comments/#isort-off

@Borda
Copy link

Borda commented Jan 20, 2021

@timothycrosley thanks for such swift reply and for this nice too
I fully understand that there can be some disagreements with other formatting tools but as far as I know flake8 is only checking compliance with PEP8, right?

@timothycrosley
Copy link
Member

This is now fixed in develop and will make its way out in the next release (5.8.0)

Thanks!

~Timothy

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

No branches or pull requests

4 participants