Skip to content

Q: Not sure how the sorting is meant to work #1973

@david-wahlstedt

Description

@david-wahlstedt

I thought the recommended way to sort was something like this:
Sections sorted alphabetically on package name:

  1. standard libraries
  2. pip packages
  3. third party libraries
  4. packages/files defined locally (in the tree where this files resides)

For two lines (capital letters are placeholders for package names or identifiers)
import A.B.C
and
from X.Y import Z

what is compared? I would choose comparing C with Y, but maybe I've not grasped it.

This doesn't seem to be the case with isort. sometimes the lines are note sorted alphabetically, and also it doesn't seem to differentiate between pip packages and local packages. I have tried it on several files, and I don't really see the pattern. It is possible to control its behavior so that it does what I want?

I'm quite new to python, and it confuses me that there doesn't seem to be one standard of how to sort the imports. Why is this?

Best regards,
David

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions