PyCQA / PyCQA/isort

Force to top should support *specific* ordering

Open
#2,130 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
7k
Forks
687
Avg merge
4h 56m
Merged PRs (30d)
2

Description

Currently when "force to top" is being used with multiple packages, then it forces all of them to the top but unfortunately does so in an alphabetical manner.

When setting:

force_to_top = ["torch", "tensorflow"]

The result will be:

import tensorflow
import torch

whereas it should be:

import torch
import tensorflow

Currently, it seems that isort does not support the ability to set multiple imports at the top of a section with a user-specified ordering. This is prohibitive because, unfortunately, some python packages have strict order import requirements.

I hope that I'm missing something! Any idea on how to solve this with isort would be much appreciated!

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No source file or test is identified in the issue. Start by searching the isort codebase for the force_to_top setting and its tests, then trace how multiple packages are ordered. Done means a configuration such as ["torch", "tensorflow"] preserves that order in the generated imports, with coverage for the behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli, tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.