Skip to content

Sort lazy import statements#2503

Open
DanielNoord wants to merge 1 commit intomainfrom
copilot/2462-sort-import-statements
Open

Sort lazy import statements#2503
DanielNoord wants to merge 1 commit intomainfrom
copilot/2462-sort-import-statements

Conversation

@DanielNoord
Copy link
Copy Markdown
Member

Asked Copilot to create a first attempt at #2462

It will require some polishing, especially in the tests. However, the approach seems sensible to me. @staticdev what do you think of this direction?

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 29, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.15%. Comparing base (22adde2) to head (07d3275).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2503   +/-   ##
=======================================
  Coverage   99.15%   99.15%           
=======================================
  Files          41       41           
  Lines        3066     3092   +26     
  Branches      662      668    +6     
=======================================
+ Hits         3040     3066   +26     
  Misses         14       14           
  Partials       12       12           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@DanielNoord DanielNoord force-pushed the copilot/2462-sort-import-statements branch from 7a1baf9 to ae33151 Compare April 15, 2026 20:49
Comment thread tests/unit/test_lazy_imports.py Outdated
Comment thread tests/unit/test_lazy_imports.py Outdated
Comment thread tests/unit/test_lazy_imports.py Outdated
Comment thread tests/unit/test_lazy_imports.py Outdated
Comment thread tests/unit/test_lazy_imports.py Outdated
Comment thread tests/unit/test_lazy_imports.py Outdated
Comment thread tests/unit/test_lazy_imports.py Outdated
Comment thread tests/unit/test_lazy_imports.py
Comment thread tests/unit/test_lazy_imports.py
@DanielNoord
Copy link
Copy Markdown
Member Author

@copilot Fix review

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
@DanielNoord DanielNoord force-pushed the copilot/2462-sort-import-statements branch from 57d0a13 to 07d3275 Compare April 15, 2026 21:29
Copy link
Copy Markdown
Member Author

@DanielNoord DanielNoord left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only DeepSource fails, but that is a stupid test anyway...

@staticdev Do you have some time to review this? I think it is actually in quite a good state now.

My plan is to merge this and release a beta version of isort. I will announce this on the original PEP thread in Discourse (and other channels if I find them) to see if users have initial feedback.
After a while we can then release an actual version. Probably somewhat after the first beta of Python 3.15.

@staticdev
Copy link
Copy Markdown
Collaborator

staticdev commented Apr 16, 2026

@DanielNoord I started reading the peps to better understand how the lazy imports will work. I will put a bit more effort to keep up and it is very cool you were already able to do some testing. This one is a big one, congratulations already for your efforts.

I will do my best to start with the code ASAP.

@DanielNoord
Copy link
Copy Markdown
Member Author

@DanielNoord I started reading the peps to better understand how the lazy imports will work. I will put a bit more effort to keep up and it is very cool you were already able to do some testing. This one is a big one, congratulations already for your efforts.

I will do my best to start with the code ASAP.

I think for now we should just mimic the behaviour of ruff, nobody benefits from us and them having different standards for the sorting.

The PEP doesn't say anything about preferred sorting order, but the order ruff implemented makes a lot of sense to me.

@DanielNoord DanielNoord requested a review from staticdev April 17, 2026 07:35
@staticdev
Copy link
Copy Markdown
Collaborator

staticdev commented Apr 17, 2026

@DanielNoord I started reading the peps to better understand how the lazy imports will work. I will put a bit more effort to keep up and it is very cool you were already able to do some testing. This one is a big one, congratulations already for your efforts.
I will do my best to start with the code ASAP.

I think for now we should just mimic the behaviour of ruff, nobody benefits from us and them having different standards for the sorting.

The PEP doesn't say anything about preferred sorting order, but the order ruff implemented makes a lot of sense to me.

Gooiemorgen,
Do you have a link of how they implemented?

@DanielNoord
Copy link
Copy Markdown
Member Author

See astral-sh/ruff#21305 :)

@DanielNoord
Copy link
Copy Markdown
Member Author

I also took their example and used it as a test case in our code!

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 this pull request may close these issues.

3 participants