black icon indicating copy to clipboard operation
black copied to clipboard

Inconsistent formatting of `**` in tenary expression.

Open randolf-scholz opened this issue 2 years ago • 2 comments

m2 = None if not isinstance(dist, Normal) else μ**2 + σ**2
m2 = None if ... else μ**2 + σ**2

becomes (black-playground)

m2 = None if not isinstance(dist, Normal) else μ ** 2 + σ**2
m2 = None if ... else μ**2 + σ**2

There are spaces added to μ**2 depending on unrelated code.

randolf-scholz avatar Jan 11 '24 13:01 randolf-scholz

Similar to #3889, which was fixed in preview mode. However, this issue is not fixed even in the preview mode. I thought we might mess up some length calculation due to the Greek letters, but that's not the case as it also reproduces with Latin letters:

% black -c  '''m2 = None if not isinstance(dist, Normal) else m**2 + s**2
m2 = None if ... else m**2 + s**2
''' --preview
m2 = None if not isinstance(dist, Normal) else m ** 2 + s**2
m2 = None if ... else m**2 + s**2

JelleZijlstra avatar Jan 11 '24 16:01 JelleZijlstra

Hi @JelleZijlstra! Please review #4154, it is my proposed to fix the bug.

wannieman98 avatar Jan 17 '24 18:01 wannieman98