Skip to content
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

force_to_top no longer moves imports to top of file. #1228

Closed
domdfcoding opened this issue Jun 12, 2020 · 6 comments
Closed

force_to_top no longer moves imports to top of file. #1228

domdfcoding opened this issue Jun 12, 2020 · 6 comments
Labels
enhancement New feature or request question Further information is requested
Milestone

Comments

@domdfcoding
Copy link

I think I am trying to use force_to_top correctly.

With the latest version on PyPI an import that is part way down the file (but not inside a function) gets moved to the appropriate section at the top of the file. However, using the current master branch the import is left where it is, although it does get the appropriate comment added above it as per my .isort.cfg file.

Is this a bug or a deliberate change in version 5?

@timothycrosley timothycrosley added the question Further information is requested label Jul 4, 2020
@timothycrosley
Copy link
Member

force_to_top, just means top within the a section not the file. isort has moved to a streaming parsing approach in 5.0.0 which allows it to safely sort around and within block of code (https://timothycrosley.github.io/isort/docs/major_releases/introducing_isort_5/) However, this does unfortunately mean it can't move imports to the top. If enough people up vote this issue I will add a feature to enable this with an acknowledgement that performance will be reduced.

@timothycrosley timothycrosley added the enhancement New feature or request label Jul 4, 2020
@pmeier
Copy link

pmeier commented Jul 5, 2020

I'd love to have this back. During development I could simply put the import statements wherever I was working currently and let isort push them to the top. If in a rare case a file needed multiple sections of imports, I simply added it to the ignore list and handled it manually.

@timothycrosley timothycrosley added this to the 5.1.0 milestone Jul 8, 2020
@timothycrosley
Copy link
Member

@pmeier This is indeed a pattern I got in the habbit of following myself as well. Aiming to get this into the next minor release

@timothycrosley
Copy link
Member

This has now been deployed to PyPI in the 5.1.0 release,
See: https://timothycrosley.github.io/isort/docs/configuration/options/#float-to-top

Thanks again!

~Timothy

@domdfcoding
Copy link
Author

Wonderful, thanks Timothy. I'll give this a try.

By the way, you spelt "guaranteed" wrong in that section of the docs (you put "gauranteed").

@timothycrosley
Copy link
Member

Thanks for letting me know :) I've updated the documentation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants