isort icon indicating copy to clipboard operation
isort copied to clipboard

BUG: --sort-reexports don't work with multiple lines __all__

Open givemepillow opened this issue 2 years ago • 2 comments

import datetime

from mylib import (
    module1,
    module2,
    module3,
    module4,
)

__all__ = (
    "func1",
    "func2",
    "func3",
    "func4",
)

after using isort file.py --sort-reexports, becomes:

import datetime

fro__all__ = ('func1', 'func2', 'func3', 'func4')

It seems to me that there is a problem with calculating the current index when using reexports in cases where we use multiline exports or add comments to the beginning of the file.

givemepillow avatar Oct 29 '23 10:10 givemepillow

Hi! I have the same problem

Before sorting:

from pomcorn.locators.base_locators import (
    Locator,
    TInitLocator,
    TLocator,
    XPathLocator,
)
from pomcorn.locators.xpath_locators import (
    ButtonWithTextLocator,
    ClassLocator,
    DataTestIdLocator,
    ElementWithTextLocator,
    IdLocator,
    InputByLabelLocator,
    NameLocator,
    PropertyLocator,
    TagNameLocator,
    TextAreaByLabelLocator,
)

__all__ = (
    "Locator",
    "XPathLocator",
    "TInitLocator",
    "TLocator",
    "ButtonWithTextLocator",
    "ClassLocator",
    "DataTestIdLocator",
    "ElementWithTextLocator",
    "IdLocator",
    "InputByLabelLocator",
    "NameLocator",
    "PropertyLocator",
    "TagNameLocator",
    "TextAreaByLabelLocator",
)

After sorting:

from __all__ = ('ButtonWithTextLocator', 'ClassLocator', 'DataTestIdLocator',
 'ElementWithTextLocator', 'IdLocator', 'InputByLabelLocator', 'Locator',
 'NameLocator', 'PropertyLocator', 'TInitLocator', 'TLocator',
 'TagNameLocator', 'TextAreaByLabelLocator', 'XPathLocator')
ByLabelLocator,
    NameLocator,
    PropertyLocator,
    TagNameLocator,
    TextAreaByLabelLocator,
)

__all__ = (

My isort config:

[tool.isort]
profile="black"
line_length=79
multi_line_output=3
skip=[
    "_tmp",
    "src",
    ".env",
    "env",
    ".venv",
    "venv",
]
known_pytest=[
    "pytest",
    "_pytest",
    "xdist",
]
sections=[
    "FUTURE",
    "STDLIB",
    "THIRDPARTY",
    "PYTEST",
    "FIRSTPARTY",
    "LOCALFOLDER",
]
include_trailing_comma=true
sort_reexports=true

M1troll avatar Nov 15 '23 03:11 M1troll

The issue still persists. It did enourmous mess with all __init__ modules in package.

daskol avatar Jul 17 '24 15:07 daskol