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?
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.
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.
@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
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
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").
Thanks for letting me know :) I've updated the documentation
Most helpful comment
@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