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

Collapse short multi-line import groups to one line with I001 #6288

Closed
andersk opened this issue Aug 2, 2023 · 6 comments
Closed

Collapse short multi-line import groups to one line with I001 #6288

andersk opened this issue Aug 2, 2023 · 6 comments

Comments

@andersk
Copy link
Contributor

andersk commented Aug 2, 2023

Ruff, like upstream isort, expands single-line import groups that are too long to multiple lines.

-from typing import Any, Callable, Dict, List, Mapping, Optional, Sequence, Tuple, TypeVar
+from typing import (
+    Any,
+    Callable,
+    Dict,
+    List,
+    Mapping,
+    Optional,
+    Sequence,
+    Tuple,
+    TypeVar,
+)

Upstream isort, but not Ruff, also does the reverse: it collapses multi-line import groups that are short enough to a single line. I think we should do this too.

-from typing import (
-    Any,
-    Callable,
-    Dict,
-    List,
-    Mapping,
-    Optional,
-    Sequence,
-    Tuple,
-)
+from typing import Any, Callable, Dict, List, Mapping, Optional, Sequence, Tuple
@charliermarsh
Copy link
Member

I believe we collapse such imports if you disable split-on-trailing-comma.

I've looked into this before, and isort's documentation states that this setting is enabled for profile = "black", but in practice it appears not to be.

@andersk
Copy link
Contributor Author

andersk commented Aug 3, 2023

It works for me (isort 5.12.0).

$ cat > a.py
from typing import (
    Any,
    Callable,
)
$ isort --profile=black a.py
Fixing /tmp/a.py
$ cat a.py
from typing import Any, Callable

@charliermarsh
Copy link
Member

What I meant is that: the isort documentation suggests that it shouldn't be removing magic trailing commas there. The documentation says that split-on-trailing-comma: true is the default for that profile. But in practice it appears not to be.

@charliermarsh
Copy link
Member

To be clear: we support this behavior, it's just not our default.

@andersk
Copy link
Contributor Author

andersk commented Aug 3, 2023

Got it. Feel free to close if you think this should remain as is.

I guess this is a duplicate of

@charliermarsh
Copy link
Member

I'm torn on it but I'm going to leave as-is for now.

@charliermarsh charliermarsh closed this as not planned Won't fix, can't repro, duplicate, stale Aug 3, 2023
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

No branches or pull requests

2 participants