black/src
Łukasz Langa 8672af35f0
Work around stability errors due to optional trailing commas (#2126)
Optional trailing commas put by Black become magic trailing commas on another
pass of the tool.  Since they are influencing formatting around optional
parentheses, on rare occasions the tool changes its mind in terms of putting
parentheses or not.

Ideally this would never be the case but sadly the decision to put optional
parentheses or not (which looks at pre-existing "magic" trailing commas) is
happening around the same time as the decision to put an optional trailing
comma.  Untangling the two proved to be impractically difficult.

This shameful workaround uses the fact that the formatting instability
introduced by magic trailing commas is deterministic: if the optional trailing
comma becoming a pre-existing "magic" trailing comma changes formatting, the
second pass becomes stable since there is no variable factor anymore on pass 3,
4, and so on.

For most files, this will introduce no performance penalty since `--safe` is
already re-formatting everything twice to ensure formatting stability.  We're
using this result and if all's good, the behavior is equivalent.  If there is
a difference, we treat the second result as the binding one, and check its
sanity again.
2021-04-25 20:15:54 +02:00
..
black Work around stability errors due to optional trailing commas (#2126) 2021-04-25 20:15:54 +02:00
black_primer Fix primer config 2021-04-25 19:44:06 +02:00
blackd Add --skip-magic-trailing-comma (#1824) 2021-01-17 16:59:06 -08:00
blib2to3 Revert "Use lowercase hex numbers fixes #1692 (#1775)" 2021-04-25 19:13:23 +02:00