|
|
Subscribe / Log in / New account

Python gets a "Developer-in-Residence"

Python gets a "Developer-in-Residence"

Posted Jul 29, 2021 19:14 UTC (Thu) by NYKevin (subscriber, #129325)
In reply to: Python gets a "Developer-in-Residence" by hynek
Parent article: Python gets a "Developer-in-Residence"

> With one exception: isort, because Black doesn’t format imports.

AIUI, this is a deliberate choice on the part of Black, because imports can have side effects.

(Imports *should not* have side effects. You should be able to reorder them without breaking anything. But bad code exists, so...)


to post comments

Python gets a "Developer-in-Residence"

Posted Jul 30, 2021 7:37 UTC (Fri) by hynek (subscriber, #55397) [Link] (1 responses)

It's even more complicated than that.

Since PEP 8 asks you to sort your import into blocks of standard library, 3rd party packages, and app packages, a non-trivial insight into the packaging situation of the current app/package is required. Thus it makes sense to punt on it, since it would open a completely new can of worms and the code is already present in isort.

Python gets a "Developer-in-Residence"

Posted Jul 31, 2021 21:57 UTC (Sat) by NYKevin (subscriber, #129325) [Link]

Right. But Black's documentation also says that it is not supposed to change the AST at all, except in a small number of special cases which should not affect runtime behavior.[1] Since import-reordering actually could change the runtime behavior, I think they consider it permanently out-of-scope, rather than just "too hard."

(As mentioned before, there is no good reason for import-reordering to change runtime behavior. It's just that Python doesn't have any hard limits which prevent you from shooting yourself in the foot like that.)

[1]: https://black.readthedocs.io/en/stable/the_black_code_sty...


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds