question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Black should alphabetize imports

See original GitHub issue

I assert black should alphabetize imports, especially like:

from .foo import (
    baz,
    bar,
    sandwich,
    fingers,
)

Should be ordered as:

from .foo import (
    bar,
    baz,
    fingers,
    sandwich
)

If it can’t I’ll get flake8 pulled in as well and have it balk at these too, even if it can’t do the reordering for us like black can.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
alyakin314commented, Sep 25, 2020

are we talking about imports within the same line or multiline imports as well? e.g. should

import numpy as np
from graspologic.inference import LatentDistributionTest
from graspologic.embed import AdjacencySpectralEmbed, LaplacianSpectralEmbed

become

from graspologic.embed import AdjacencySpectralEmbed, LaplacianSpectralEmbed
from graspologic.inference import LatentDistributionTest
import numpy as np

because personally i am more of a fan of imports that look like christmas tree and go from general (numpy as np, pandas as pd, etc.) to specific (from graspologic.embed import AdjacencySpectralEmbed, LaplacianSpectralEmbed). but that’s just my 2 cents.

0reactions
daxprycecommented, Nov 18, 2021

This has been added by requiring isort balking if it doesn’t like the order

Read more comments on GitHub >

github_iconTop Results From Across the Web

Black should re-order imports like isort #573 - GitHub
We are currently working on implementing an isort + black to format the code base and sort imports as well, but it would...
Read more >
Black doesn't sort imports at all. - Hacker News
And PEP 8 doesn't mention sorting the imports. There are even counterexamples which aren't alphabetically sorted. It does mention grouping ...
Read more >
Using Black with other tools - Black 22.12.0 documentation
Why those options above?# ... Black wraps imports that surpass line-length by moving identifiers into their own indented line. If that still doesn't...
Read more >
Python & VS Code: make Black and organize imports work ...
I use Black to format my Python code, and I tell VS Code to organise ... It turns out that VS Code uses...
Read more >
Can Black be configured to ignore imports? - Stack Overflow
While I do not mind the way Black sorts my imports, I would still like to use isort to handle my imports and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found