|
|
Subscribe / Log in / New account

Python gets a "Developer-in-Residence"

Python gets a "Developer-in-Residence"

Posted Jul 29, 2021 7:53 UTC (Thu) by hynek (subscriber, #55397)
In reply to: Python gets a "Developer-in-Residence" by LtWorf
Parent article: Python gets a "Developer-in-Residence"

As someone who has used Black since the earliest alphas, I have to say this is a misrepresentation.

Łukasz and his team are doing their best to keep changes meaningful and at a minimum. It has been _months_ since it happened to any of my many code bases, and it was always worth it.

> Interestingly formatting a formatted code with a newer version and then reformatting with the older version will not reset the format completely.

Since Black goes for a canonical code form, the only reason why this could be true is a bug. Software sometimes has bugs, it's sad but true. On the other hand, YELLING that nobody should should use Black is rude FUD. It certainly isn't an outlier bug-wise.


to post comments

Python gets a "Developer-in-Residence"

Posted Jul 29, 2021 10:05 UTC (Thu) by rsidd (subscriber, #2582) [Link] (9 responses)

Thanks. I hadn't encountered Black before, but on reading the docs, it certainly looks like any version differences are minor and shouldn't restyle everything (if already restyled by a previous version of Black). But it does sound like you should use only Black and not mix it with any other styler. So the shouty comment does sound like FUD. The author probably had a genuine bad experience, but there are more productive ways to share it.

Python gets a "Developer-in-Residence"

Posted Jul 29, 2021 12:28 UTC (Thu) by hynek (subscriber, #55397) [Link] (5 responses)

Yes, since Black formats everything to a canonical shape, it makes no sense to have other formatters.

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

Python gets a "Developer-in-Residence"

Posted Jul 29, 2021 19:14 UTC (Thu) by NYKevin (subscriber, #129325) [Link] (2 responses)

> 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...)

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...

Python gets a "Developer-in-Residence"

Posted Jul 30, 2021 8:22 UTC (Fri) by rsidd (subscriber, #2582) [Link] (1 responses)

If I understand the Black docs right, Black formats imports (I just checked: it does), but doesn't sort them?

Python gets a "Developer-in-Residence"

Posted Jul 30, 2021 14:01 UTC (Fri) by kpfleming (subscriber, #23250) [Link]

Correct. (plus some characters)

Python gets a "Developer-in-Residence"

Posted Jul 31, 2021 7:43 UTC (Sat) by LtWorf (subscriber, #124958) [Link] (2 responses)

> So the shouty comment does sound like FUD. The author probably had a genuine bad experience, but there are more productive ways to share it.

It's not FUD if it's real.

It's a tool that in theory wants to be like go fmt, but in practice isn't, and creates the need to reformat the whole codebase (and pollute commit history) periodically.

Python gets a "Developer-in-Residence"

Posted Jul 31, 2021 10:53 UTC (Sat) by rsidd (subscriber, #2582) [Link] (1 responses)

It aims to minimize diffs. The version-to-version changes suggest that some small specific bits, at most, would be reformatted, so the diff from formatting a previously Black-formatted file with a new Black version should be tiny.

If you really have an example where the entire file was changed by a new version of Black, why not report that as a bug? I don't see how that can happen with any format tool, actually.

Python gets a "Developer-in-Residence"

Posted Jul 31, 2021 13:42 UTC (Sat) by mathstuf (subscriber, #69389) [Link]

> I don't see how that can happen with any format tool, actually.

The usual culprits in my experience include (in a rough order):

- line length breaking heuristics
- updates to the language (e.g., C++03 → C++11 made lots of "> >" → ">>" diff noise)
- more insight into comments (reflowing paragraphs or such) or macros

Python gets a "Developer-in-Residence"

Posted Jul 31, 2021 7:42 UTC (Sat) by LtWorf (subscriber, #124958) [Link] (2 responses)

> It has been _months_ since it happened

It should just not happen, because commits that change hundreds of files at once, with "style" as description make going back in history incredibly hard.

Python gets a "Developer-in-Residence"

Posted Jul 31, 2021 15:21 UTC (Sat) by rsidd (subscriber, #2582) [Link] (1 responses)

You have a python project with hundreds of files? That was bitten by this issue where every file was totally changed by a new version of black? Is it then that hard to report a bug, saying, file example x formatted by black version y, then reformatted by black version z, has an enormous diff?

Python gets a "Developer-in-Residence"

Posted Jul 31, 2021 17:51 UTC (Sat) by LtWorf (subscriber, #124958) [Link]

Since I only use stable distributions, how is that going to help? The authors can't change the past, and any "fix" will only generate more diff.

My issue is more on the general approach of the project, that seems to be ok with periodically having to reformat stuff.


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