3 ms·
Flake8 Alphabetize will just give you warnings about import order, whereas isort will actually change the code itself. So as I see it there are two types of to
by tlocke 5y ago
Flake8 Alphabetize will just give you warnings about import order, whereas isort will actually change the code itself.
So as I see it there are two types of tool, formatters and checkers. A formatter doesn't alter the Abstract Syntax Tree (AST). In other words it doesn't alter the meaning of the code, just how it looks (eg. the formatter Black). A checker on the other hand looks only at the AST and just gives warnings in your editor, and then it's up to you to change it or not.
The import order is fixed in the AST, so it falls outside the scope of Black (which never changes the AST). So I felt there was a need for a tool that worked as a checker that just gives warnings in your editor if your imports don't conform to PEP8, and hence Flake8 Alphabetize.
It's worth mentioning that Flake8 Alphabetize follows Black's philosophy of having only one way of doing things, so a project can standardise on Flake8 Alphabetize and everyone's imports will look the same.
Anyway, any feedback is welcomed:-)
- claytonjy 5y agoThe checker/formatter distinction makes a lot of sense. Given the choice between the two for a given goal or set of operations, e.g. alphabetize/isort, I'm not sure why I'd settle for a checker. If the fix is deterministic and objective, why would I want to make the fix myself, rather than let the tool handle it?
- tlocke 5y agoMy feeling is that I want anything that could change the meaning of the code to be down to me making a manual edit. So I'm quite happy for the Black formatter to automatically rewrite my code as it never changes its meaning. For anything else I like to be in the driving seat. Anyway, that's just my feeling at the moment, I'm sure others have a different take.