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: --sort-reexports don't work with multiple lines __all__ #2193

Open
givemepillow opened this issue Oct 29, 2023 · 2 comments · May be fixed by #2283
Open

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

givemepillow opened this issue Oct 29, 2023 · 2 comments · May be fixed by #2283

Comments

@givemepillow
Copy link

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.

@M1troll
Copy link

M1troll commented Nov 15, 2023

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

@daskol
Copy link

daskol commented Jul 17, 2024

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

daskol added a commit to nntile/nntile that referenced this issue Jul 17, 2024
Also, there is a bug in `isort` related to reexport sorting (see
PyCQA/isort#2193 for details).
@Helveg Helveg linked a pull request Jul 27, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants