-
-
Notifications
You must be signed in to change notification settings - Fork 597
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
isort should not move imports past other code #693
Comments
Oops, I missed #468; this is a duplicate of it. |
While waiting for the release of the features that'll allow it, here is my workaround. I put the patching and path altering commands their own module, so they are triggered by an import statement in the original file. Then using isort configuration, one can control the position of this import, for example making it it's own section and controlling the order of it. Before:
After:
Configure isort with:
|
Currently, if you have a file like:
then isort will move the two later imports up to go above the
sys.path
line. But you probably put it after thesys.path
line because you need that path modification to findfoo
!What I would expect isort to do here is to treat two import blocks that have a non-import statement in between as completely separate: that is, it should sort the block with
import sys
(trivial), and separately sort the block withimport foo
andimport bar
(swap the two), but not mix those two blocks together.(This behavior could, of course, be optional, although I'd argue it's the right behavior for most cases; it's not the job of isort to decide whether having that code in the middle of your imports was a good idea. A linter is better suited to do that; and it would allow you to
# noqa
the offending line if you really do want it.)The text was updated successfully, but these errors were encountered: