facebook / usort

Safe, minimal import sorting for Python projects.
https://usort.readthedocs.io
MIT License
189 stars 22 forks source link

usort drops inline comments in multi-line imports without trailing commas #249

Closed amyreese closed 1 year ago

amyreese commented 1 year ago

Source file:

from base import (  # one
    # two
    a,  # three
    b  # four
    # five
)  # six

Repro:

(venv) amethyst@luxray ~/scratch/usort-bug » usort diff source.py
--- a/source.py
+++ b/source.py
@@ -1,7 +1,2 @@
-from base import (  # one
-    # two
-    a,  # three
-    b  # four
-    # five
-)  # six
+from base import a, b  # one  # two  # three  # five  # six

With line-length=20 to prevent collapsing to single line:

(venv) amethyst@luxray ~/scratch/usort-bug » usort diff source.py
--- a/source.py
+++ b/source.py
@@ -1,7 +1,7 @@
 from base import (  # one
     # two
     a,  # three
-    b  # four
+    b,
     # five
 )  # six

Note that in both cases, comment # four is dropped from the final result.