PyCQA / PyCQA/isort

Add option to place absolute import above relative import in the same section

Open
#2,146 1 comment 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

We have most local imports in relative format, but we have some absolute imports that should be grouped together with them.
I have added the packages with "--known-local-folder". The absolute imports we wanted in LOCALFOLDER section did move as intended, but sorted after the relative imports:

from ..foo import bar
from .hoge import piyo
from some_package.foo import baz

We’d rather want to have absolute imports above relative imports within the section:

from some_package.foo import baz
from ..foo import bar
from .hoge import piyo

Is there any option to achieve above result?

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

Start by tracing the --known-local-folder option and the import sorting logic that orders absolute and relative imports within the LOCALFOLDER section. Confirm the expected ordering with the examples in this issue and add or update coverage for both orderings before considering the change done.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.