Re:Guietta – Python module to create simple GUIs
by skocznymroczny on Friday July 03, 2020 @04:40AM
(#23722212)
Some of Python linters enforce such style. If you enable pylint or black I think they do that by default.
[ Parent
| on HN ]
Re:Guietta – Python module to create simple GUIs
by diarrhea on Friday July 03, 2020 @05:29AM
(#23722469)
black sorts alphabetically, with standard lib first, then 3rd party imports, and user/local imports last. Blocks are separated by a blank line. `from ..` imports come after `import ..`.
Especially the alphabetic ordering is important in my view. Makes parsing/reading and spotting duplicates much easier. It is also PEP8 style [0].
For all these reasons, I think the pyramid style is awful in comparison.
Re:Guietta – Python module to create simple GUIs
by StavrosK on Friday July 03, 2020 @07:45AM
(#23723159)
Black doesn't sort imports at all.
Re:Guietta – Python module to create simple GUIs
by spappal on Saturday July 04, 2020 @12:33PM
(#23733337)
And PEP 8 doesn't mention sorting the imports. There are even counterexamples which aren't alphabetically sorted. It does mention grouping though.
Since Python imports can have side effects, the order can matter. But to the extent that it doesn't break anything, alphabetically sorted groups seems deterministic and readable.
I think this might be the most popular implementation for auto-sorting: https://pypi.org/project/isort/