Repository navigation
Conversation
isort attaches comments to the import statements they belong to rather than to a position in the file, so a comment can end up somewhere other than where it was written. Nothing in the docs described this, which led to PyCQA#1843. Document where comments end up: - a comment directly above an import is sorted with it, and a blank line above the comment does not detach it - a comment detached from every import stays put - a comment on its own line inside a multiline import moves to the line that opens the import - a trailing comment on an imported name is kept with that name, putting the name on its own from-import - when a module is imported more than once, a comment attached to a later statement floats above the first statement for that module Each example is checked against the current isort output. Closes: PyCQA#1843
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1843
isort moves comments around when it sorts, and until now nothing documented the rules, so the behaviour looked arbitrary. The new
docs/configuration/comments.mdpage explains:from ... importblock stay attached to their name, so the whole block is reordered around themforce_sort_within_sections,ignore_comments,float_to_top)Each rule is shown as a before/after pair.
Testing: the before/after examples are all real
isortoutput, produced by runningisortwith the default settings (plus the variants named in each example) on the inputs shown.nox -s docsbuilds without warnings, so the new page is wired into the docs navigation correctly. I could not run the fullnoxtest suite in this environment; no isort code was changed, so the behaviour described here is unchanged by this PR.