-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
isort: Add support for the from-first
setting
#8663
Conversation
|
bbebe81
to
30fcf8a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we instead explore incorporating this into ModuleKey
and MemberKey
? We carved those out recently to make the sorting easier to modify.
How to do that doesn't seem obvious to me - I'd be grateful for some feedback. from_first applies in isort even if force_within_sections is not enabled; see https://github.com/PyCQA/isort/blob/c574c4c190ceddb66b10330ae811a95306f07b74/isort/output.py#L90 I could add something like ModuleKey, e.g. ImportTypeKey? Alternatively perhaps a |
@bluthej - Curious if you have any thoughts on how |
I guess I would have done something along those lines, the only thing is I don't see why we need a The alternative would be to add an item in FWI I just submitted a quick PR that moves some of this logic into |
I had trouble coercing rust into thinking that the two iterators were the same type - the only way I managed to was with a box. That's probably just my ignorance on the rust side.. |
This setting behaves similarly to the ``from_first`` setting in isort upstream, and sorts "from X import Y" type imports before straight imports. Fixes astral-sh#8662
30fcf8a
to
830cec5
Compare
@charliermarsh PTAL; now updated after the recent refactoring. It no longer uses box, and mimicks the behaviour in isort. |
@charliermarsh I had a closer look at the changes (sorry for the delay, I've been kind of swamped). I personally think this implementation is the way to go. In my mind, the items in @jelmer I had a feeling My only comment is that there does not seem to be any interaction between this setting and |
I agree. Do you have a sense of how to make that change? It may just be easier to put up a separate PR on top of this one and I can merge them in order. |
The most straightforward way to fix it would be to add But I don't know what the general policy is regarding incompatible settings in Ruff, do you usually make one setting silently override the other or do you throw an error and notify the user that their config is inconsistent? |
@bluthej My setup actually relies on both The |
@jelmer I'm sorry my message was totally confusing, what I really meant to say was that there does not seem to be any interaction between |
But that makes me think this PR is fine, I'll open a separate issue for that. |
Ah, sorry, I did indeed misunderstand. That makes sense to me though - both your comments on force_sort_within_sections and lines_between_types interactions, and doing that as a separate change. |
338ea22
to
b34e3b8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Summary
This setting behaves similarly to the
from_first
setting in isort upstream, and sorts "from X import Y" type imports before straight imports.Like the other PR I added, happy to refactor if this is better in another form.
Fixes #8662
Test plan
I've added a unit test, and ran this on a large codebase that relies on this setting in isort to verify it doesn't have unexpected side effects.