Custom implementation of import sorting. #329
Merged
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.
This tries to implement some of the rule of import sorting as requested in #13 using custom logic, This was originally fixed in #263 using isort, but reverted and re-requested as of #287
Current this has the following limitations/bugs that will need to be sorted out, but might need fixes to Pyflyby master branch first.
This can be tried with the
--experimental-sort-imports
from __future__ import ...
, to always be followed by a blank line, it is currently not the case if the next lexicographic import is a single import.from __future__ import ...
is not always inserted before the first blank lines in the file,from __future__ import...
do not get the same treatment with respect to aligning with space, but it's unclear wether this is a bug (and it can be solved separately).C, (and likely B), is I think a bug in Pyflyby parsing where new lines are part of the next statement (especially if it is a comment) instead of being part of the previous one – or being their own statement. It might affect strings literal as well (to check). See #328
From what I can tell this may change API, so I want to be careful fixing this.