-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Preserve comments when sorting imports #749
Conversation
72041bc
to
5ed4a4e
Compare
I'll add a few examples here tomorrow. |
There’s a slight Black incompatibility—Black requires this newline: import math
import os
# a comment
import pathlib
import sys while Ruff deletes it: import math
import os
# a comment
import pathlib
import sys |
Comments seem to be unexpectedly counted toward the length of the following line in some cases, causing the following import to wrap early: import a
# ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
from b import c → import a
# ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
from b import (
c,
) |
Woo thanks for trying! I noticed the second issue when running on Zulip :) It's late here so will fix these both tomorrow (then hopefully merge). |
Multi-line comments are unexpectedly sorted and deduplicated: import io
# Old MacDonald had a farm,
# EIEIO
# And on his farm he had a cow,
# EIEIO
# With a moo-moo here and a moo-moo there
# Here a moo, there a moo, everywhere moo-moo
# Old MacDonald had a farm,
# EIEIO
from errno import EIO → import io
# And on his farm he had a cow,
# EIEIO
# Here a moo, there a moo, everywhere moo-moo
# Old MacDonald had a farm,
# With a moo-moo here and a moo-moo there
from errno import (
EIO,
) |
5ed4a4e
to
30a23b5
Compare
dba0f7f
to
f6e19e7
Compare
f6e19e7
to
deab5c8
Compare
It's tough to come up with a strategy that does the "right" thing in all cases (in part, because it's hard to even define the "right" output in every case), but this PR preserves all comments, is stable across re-runs, and tries to do sensible things when merging across imports.
Resolves #675.